473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validate my form and header to another success page

22 New Member
I am trying to validate my form fields and redirect the user to success page

so this is the PHP code

Expand|Select|Wrap|Line Numbers
  1. if (empty($_POST['experiences'])) {
  2.         $error['experiencesErr'] = "Experiences Required";
  3.     } else {
  4.         $experiences = check_input($_POST['experiences']);
  5.         if (!preg_match("/^[0-9_a-zA-Z ]*$/", $experiences)) {
  6.             $error['experiencesErr'] = "Only letters, numbers and '_' allowed";
  7.         }
  8.     }
  9.  
  10.     $courses = check_input($_POST['courses']);
  11.     if (!preg_match("/^[0-9_a-zA-Z ]*$/", $courses)) {
  12.         $error['coursesErr'] = "Only letters, numbers and '_' allowed";
  13.     }
  14.  
  15.     $careerObjective = check_input($_POST['careerObjective']);
  16.     if (!preg_match("/^[0-9_a-zA-Z ]*$/", $careerObjective)) {
  17.         $error['careerObjectiveErr'] = "Only letters, numbers and '_' allowed";
  18.     }
  19.  
  20.     if (empty($_POST['availability'])) {
  21.         $error['availabilityErr'] = "Availability Required";
  22.     } else {
  23.         $availability = check_input($_POST['availability']);
  24.     }
  25.  
  26.     if (empty($_POST['typeOfJob'])) {
  27.         $error['typeOfJobErr'] = "Full/Part Time Required";
  28.     } else {
  29.         $typeOfJob = check_input($_POST['typeOfJob']);
  30.     }
  31.  
  32.     if (empty($_POST['typeOfJob'])) {
  33.         $error['typeOfJobErr'] = "Full/Part Time Required";
  34.     } else {
  35.         $typeOfJob = check_input($_POST['typeOfJob']);
  36.     }
  37.  
  38.     if (empty($_POST['rank'])) {
  39.         $error['rankErr'] = "Self-assessment Required";
  40.     } else {
  41.         $rank = check_input($_POST['rank']);
  42.     }
  43.  
  44.     if (empty($_POST['jTitle'])) {
  45.         $error['jTitleErr'] = "Job Field Required";
  46.     } else {
  47.         $jTitle = check_input($_POST['jTitle']);
  48.     }
  49.  
  50.     $otherJobTitle = check_input($_POST['otherJobTitle']);
  51.     if (!preg_match("/^[0-9_a-zA-Z ]*$/", $otherJobTitle)) {
  52.         $error['otherJobTitleErr'] = "Only letters, numbers and '_' allowed";
  53.     }
  54.  
  55.     if (empty($_POST['salaryRange'])) {
  56.         $error['salaryRangeErr'] = "Salary Range Required";
  57.     } else {
  58.         $salaryRange = check_input($_POST['salaryRange']);
  59.     }
  60.  
  61.     if (empty($_POST['currency'])) {
  62.         $error['currencyErr'] = "Currency Required";
  63.     } else {
  64.         $currency = check_input($_POST['currency']);
  65.     }
  66.  
  67.     $workIn = check_input($_POST['workIn']);
  68.  
  69.     if(!$error){
  70.         $putData = $db->prepare("INSERT INTO hired_ts_info (id, uid, experiences, courses, career_objective,
  71.         availability, type_of_job, rank, job_title, other_job_title, salary_range, currency, workIn)
  72.         VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  73.  
  74.         $putData->bind_param('iisssssssssss', $id, $uid, $experiences, $courses, $careerObjective, $availability,
  75.         $typeOfJob, $rank, $jTitle, $otherJobTitle, $salaryRange, $currency, $workIn);
  76.  
  77.         if($putData->execute()){
  78.             header("Location:?pid=4&pp=2&pps=technicalSummary&m=g");
  79.         }else{
  80.             echo "Error on executing";
  81.         }
  82.     }
  83. }
  84. ?>
  85.  
and this is the first lines of the HTML code

Expand|Select|Wrap|Line Numbers
  1. <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" id="personRegestrationPage4">
  2.  
  3.  
  4. <div class="f_left width100percent">
  5.     <div class="TwoLine">
  6.         <label for="experiences" class="requiredFields">experiences and qualifications</label>
  7.         <textarea name="experiences" id="experiences"></textarea>
  8.         <span class="notAllowed"><?php if (isset($error)) {
  9.                 echo $error['experiencesErr'];
  10.             }?></span>
  11.     </div>
  12.  
  13.     <div class="TwoLine">
  14.         <label for="courses">Previous Courses</label>
  15.         <textarea name="courses" id="courses"></textarea>
  16.         <span class="notAllowed"><?php if (isset($error)) {
  17.                 echo $error['coursesErr'];
  18.             } ?></span>
  19.     </div>
  20. </div>
  21.  
and this is the submit button code

Expand|Select|Wrap|Line Numbers
  1. <input type="submit" name="subTs" id="subTs" value="Save Changes" class="submitBtn4">
Update
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', 1);
  5.  
  6.  
  7. $experiences = $courses = $careerObjective = $availability = $typeOfJob = $rank = $jTitle = $otherJobTitle
  8.     = $salaryRange = $currency = $workIn = "";
  9.  
  10. $experiencesErr = $coursesErr = $careerObjectiveErr = $availabilityErr = $typeOfJobErr = $rankErr = $jTitleErr
  11.     = $otherJobTitleErr = $salaryRangeErr = $currencyErr = $workInErr = "";
  12.  
  13.  
  14. $id = "";
  15. $uid = "";
  16.  
  17. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  18.     $error = array();
  19.  
  20.     if (empty($_POST['experiences'])) {
  21.         $error['experiencesErr'] = "Experiences Required";
  22.     } else {
  23.         $experiences = check_input($_POST['experiences']);
  24.         if (!preg_match("/^[0-9_a-zA-Z ]*$/", $experiences)) {
  25.             $error['experiencesErr'] = "Only letters, numbers and '_' allowed";
  26.         }
  27.     }
  28.  
  29.     $courses = check_input($_POST['courses']);
  30.     if (!preg_match("/^[0-9_a-zA-Z ]*$/", $courses)) {
  31.         $error['coursesErr'] = "Only letters, numbers and '_' allowed";
  32.     }
  33.  
  34.     $careerObjective = check_input($_POST['careerObjective']);
  35.     if (!preg_match("/^[0-9_a-zA-Z ]*$/", $careerObjective)) {
  36.         $error['careerObjectiveErr'] = "Only letters, numbers and '_' allowed";
  37.     }
  38.  
  39.     if (empty($_POST['availability'])) {
  40.         $error['availabilityErr'] = "Availability Required";
  41.     } else {
  42.         $availability = check_input($_POST['availability']);
  43.     }
  44.  
  45.     if (empty($_POST['typeOfJob'])) {
  46.         $error['typeOfJobErr'] = "Full/Part Time Required";
  47.     } else {
  48.         $typeOfJob = check_input($_POST['typeOfJob']);
  49.     }
  50.  
  51.     if (empty($_POST['typeOfJob'])) {
  52.         $error['typeOfJobErr'] = "Full/Part Time Required";
  53.     } else {
  54.         $typeOfJob = check_input($_POST['typeOfJob']);
  55.     }
  56.  
  57.     if (empty($_POST['rank'])) {
  58.         $error['rankErr'] = "Self-assessment Required";
  59.     } else {
  60.         $rank = check_input($_POST['rank']);
  61.     }
  62.  
  63.     if (empty($_POST['jTitle'])) {
  64.         $error['jTitleErr'] = "Job Field Required";
  65.     } else {
  66.         $jTitle = check_input($_POST['jTitle']);
  67.     }
  68.  
  69.     $otherJobTitle = check_input($_POST['otherJobTitle']);
  70.     if (!preg_match("/^[0-9_a-zA-Z ]*$/", $otherJobTitle)) {
  71.         $error['otherJobTitleErr'] = "Only letters, numbers and '_' allowed";
  72.     }
  73.  
  74.     if (empty($_POST['salaryRange'])) {
  75.         $error['salaryRangeErr'] = "Salary Range Required";
  76.     } else {
  77.         $salaryRange = check_input($_POST['salaryRange']);
  78.     }
  79.  
  80.     if (empty($_POST['currency'])) {
  81.         $error['currencyErr'] = "Currency Required";
  82.     } else {
  83.         $currency = check_input($_POST['currency']);
  84.     }
  85.  
  86.     $workIn = check_input($_POST['workIn']);
  87.  
  88.     if (!$error) {
  89.         $putData = $db->prepare("INSERT INTO hired_ts_info (id, uid, experiences, courses, career_objective,
  90.         availability, type_of_job, rank, job_title, other_job_title, salary_range, currency, workIn)
  91.         VALUE(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  92.  
  93.         $putData->bind_param('iisssssssssss', $id, $uid, $experiences, $courses, $careerObjective, $availability,
  94.             $typeOfJob, $rank, $jTitle, $otherJobTitle, $salaryRange, $currency, $workIn);
  95.  
  96.         if ($putData->execute()) {
  97.             header("Location:?pid=4&pp=2&pps=technicalSummary&m=g");
  98.         } else {
  99.             echo "Error on executing";
  100.         }
  101.     } else {
  102.         $error = array(
  103.             "coursesErr" => "",
  104.             "careerObjectiveErr" => "",
  105.             "otherJobTitleErr" => "",
  106.             "experiencesErr" => "",
  107.             "availabilityErr" => "",
  108.             "typeOfJobErr" => "",
  109.             "rankErr" => "",
  110.             "jTitleErr" => "",
  111.             "salaryRangeErr" => "",
  112.             "currencyErr" => "",
  113.         );
  114.     }
  115. }
  116. ?>
  117.  

**still that didn't solve the issue **

1- now the code submit correctly and gos to my DB.
2- if the fields is empty or not allowed input the message don't appear any more under the fields
any Ideas please

Thanks
Aug 18 '14 #1
0 1093

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2116
by: eric rudolph | last post by:
I am writing a photo gallery and suppose 8 photos are displayed. When the user clicks on a button under the picture, I want it to add that picture name to a "favorites" list within the session data, but NOT leave the page the user is on. How could I do this? thanks
2
5071
by: luu duong | last post by:
I know this is probably easy but here is the details. I have an asp page that is not inside a frameset. I want to post data to another asp page that is inside a frameset. So firstpage.asp has action="response.htm" target="results". response.htm... <HTML> <FRAMESET ROWS="50%,50%"> <FRAME SRC="header.asp" NAME="fTop"> <FRAME...
27
6170
by: Oscar | last post by:
I am looking for a way to pass an ADO recordset that has been retrieved in an ASP page to another HTML-page. Is there someone who can provide me with a small sample or a link to see how this is done? regards, Oscar
10
6593
by: iam247 | last post by:
Hi In my prototype asp page (with no javascript and no password validation, I have a registration form with the following action: <form name="form" method="post" action="RegDetails.asp"> This works fine, the form details are collected by RegDetails.asp I am attempting to include javascript server side validation for the
3
57908
by: John Baker | last post by:
Hi: I have developed a form, commencing with the form wizard showing in Design View. Having developed the form partially, I wanted to put a page header on it which would contain the controls. I set up the header in Design view, but when I switch to Form view the header does not show. Is there something I am doing wrong or is there some...
4
4788
by: tom | last post by:
Hi Experts, I want to pass the selectedDate value from my calender form to another web form or a web user control. Could you please show me how to do this? Thanks in advance.
4
1617
by: Newbie | last post by:
Hi, I need help in posting asp .net application web form to another asp based web app. I have seen many examples using HttpWebRequest class but the problem is I do not want the request back but want to post the data to another form so that at the asp page level we can use request.form values. Any leads would definately be appreciated.
1
359
by: jayparaiso | last post by:
Hi! How to validate check box and drop down menu in one form?
4
4341
by: MichaelK | last post by:
Hello. I have all data already collected on the current page? I want to open another window with the form, fill the fields and submit that form. So basically the question is how can I fill all fields and submit the form on another window. Regards, Michael
0
1310
by: munkee | last post by:
Hi all, I am currently getting to grips with visual studio web developer 2010. I have created a web form in vb which I have submitting to a SQL express 2008 database. I want to produce a submission success page where I can show the record that has just been added including the primary key which is incremental that I use as a reference...
0
7711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7805
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
755
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.