I am trying to validate my form fields and redirect the user to success page
so this is the PHP code
and this is the first lines of the HTML code
and this is the submit button code
Update
**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
so this is the PHP code
Code:
if (empty($_POST['experiences'])) { $error['experiencesErr'] = "Experiences Required"; } else { $experiences = check_input($_POST['experiences']); if (!preg_match("/^[0-9_a-zA-Z ]*$/", $experiences)) { $error['experiencesErr'] = "Only letters, numbers and '_' allowed"; } } $courses = check_input($_POST['courses']); if (!preg_match("/^[0-9_a-zA-Z ]*$/", $courses)) { $error['coursesErr'] = "Only letters, numbers and '_' allowed"; } $careerObjective = check_input($_POST['careerObjective']); if (!preg_match("/^[0-9_a-zA-Z ]*$/", $careerObjective)) { $error['careerObjectiveErr'] = "Only letters, numbers and '_' allowed"; } if (empty($_POST['availability'])) { $error['availabilityErr'] = "Availability Required"; } else { $availability = check_input($_POST['availability']); } if (empty($_POST['typeOfJob'])) { $error['typeOfJobErr'] = "Full/Part Time Required"; } else { $typeOfJob = check_input($_POST['typeOfJob']); } if (empty($_POST['typeOfJob'])) { $error['typeOfJobErr'] = "Full/Part Time Required"; } else { $typeOfJob = check_input($_POST['typeOfJob']); } if (empty($_POST['rank'])) { $error['rankErr'] = "Self-assessment Required"; } else { $rank = check_input($_POST['rank']); } if (empty($_POST['jTitle'])) { $error['jTitleErr'] = "Job Field Required"; } else { $jTitle = check_input($_POST['jTitle']); } $otherJobTitle = check_input($_POST['otherJobTitle']); if (!preg_match("/^[0-9_a-zA-Z ]*$/", $otherJobTitle)) { $error['otherJobTitleErr'] = "Only letters, numbers and '_' allowed"; } if (empty($_POST['salaryRange'])) { $error['salaryRangeErr'] = "Salary Range Required"; } else { $salaryRange = check_input($_POST['salaryRange']); } if (empty($_POST['currency'])) { $error['currencyErr'] = "Currency Required"; } else { $currency = check_input($_POST['currency']); } $workIn = check_input($_POST['workIn']); if(!$error){ $putData = $db->prepare("INSERT INTO hired_ts_info (id, uid, experiences, courses, career_objective, availability, type_of_job, rank, job_title, other_job_title, salary_range, currency, workIn) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $putData->bind_param('iisssssssssss', $id, $uid, $experiences, $courses, $careerObjective, $availability, $typeOfJob, $rank, $jTitle, $otherJobTitle, $salaryRange, $currency, $workIn); if($putData->execute()){ header("Location:?pid=4&pp=2&pps=technicalSummary&m=g"); }else{ echo "Error on executing"; } } } ?>
Code:
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" id="personRegestrationPage4"> <div class="f_left width100percent"> <div class="TwoLine"> <label for="experiences" class="requiredFields">experiences and qualifications</label> <textarea name="experiences" id="experiences"></textarea> <span class="notAllowed"><?php if (isset($error)) { echo $error['experiencesErr']; }?></span> </div> <div class="TwoLine"> <label for="courses">Previous Courses</label> <textarea name="courses" id="courses"></textarea> <span class="notAllowed"><?php if (isset($error)) { echo $error['coursesErr']; } ?></span> </div> </div>
Code:
<input type="submit" name="subTs" id="subTs" value="Save Changes" class="submitBtn4">
Code:
<?php error_reporting(E_ALL); ini_set('display_errors', 1); $experiences = $courses = $careerObjective = $availability = $typeOfJob = $rank = $jTitle = $otherJobTitle = $salaryRange = $currency = $workIn = ""; $experiencesErr = $coursesErr = $careerObjectiveErr = $availabilityErr = $typeOfJobErr = $rankErr = $jTitleErr = $otherJobTitleErr = $salaryRangeErr = $currencyErr = $workInErr = ""; $id = ""; $uid = ""; if ($_SERVER['REQUEST_METHOD'] == "POST") { $error = array(); if (empty($_POST['experiences'])) { $error['experiencesErr'] = "Experiences Required"; } else { $experiences = check_input($_POST['experiences']); if (!preg_match("/^[0-9_a-zA-Z ]*$/", $experiences)) { $error['experiencesErr'] = "Only letters, numbers and '_' allowed"; } } $courses = check_input($_POST['courses']); if (!preg_match("/^[0-9_a-zA-Z ]*$/", $courses)) { $error['coursesErr'] = "Only letters, numbers and '_' allowed"; } $careerObjective = check_input($_POST['careerObjective']); if (!preg_match("/^[0-9_a-zA-Z ]*$/", $careerObjective)) { $error['careerObjectiveErr'] = "Only letters, numbers and '_' allowed"; } if (empty($_POST['availability'])) { $error['availabilityErr'] = "Availability Required"; } else { $availability = check_input($_POST['availability']); } if (empty($_POST['typeOfJob'])) { $error['typeOfJobErr'] = "Full/Part Time Required"; } else { $typeOfJob = check_input($_POST['typeOfJob']); } if (empty($_POST['typeOfJob'])) { $error['typeOfJobErr'] = "Full/Part Time Required"; } else { $typeOfJob = check_input($_POST['typeOfJob']); } if (empty($_POST['rank'])) { $error['rankErr'] = "Self-assessment Required"; } else { $rank = check_input($_POST['rank']); } if (empty($_POST['jTitle'])) { $error['jTitleErr'] = "Job Field Required"; } else { $jTitle = check_input($_POST['jTitle']); } $otherJobTitle = check_input($_POST['otherJobTitle']); if (!preg_match("/^[0-9_a-zA-Z ]*$/", $otherJobTitle)) { $error['otherJobTitleErr'] = "Only letters, numbers and '_' allowed"; } if (empty($_POST['salaryRange'])) { $error['salaryRangeErr'] = "Salary Range Required"; } else { $salaryRange = check_input($_POST['salaryRange']); } if (empty($_POST['currency'])) { $error['currencyErr'] = "Currency Required"; } else { $currency = check_input($_POST['currency']); } $workIn = check_input($_POST['workIn']); if (!$error) { $putData = $db->prepare("INSERT INTO hired_ts_info (id, uid, experiences, courses, career_objective, availability, type_of_job, rank, job_title, other_job_title, salary_range, currency, workIn) VALUE(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $putData->bind_param('iisssssssssss', $id, $uid, $experiences, $courses, $careerObjective, $availability, $typeOfJob, $rank, $jTitle, $otherJobTitle, $salaryRange, $currency, $workIn); if ($putData->execute()) { header("Location:?pid=4&pp=2&pps=technicalSummary&m=g"); } else { echo "Error on executing"; } } else { $error = array( "coursesErr" => "", "careerObjectiveErr" => "", "otherJobTitleErr" => "", "experiencesErr" => "", "availabilityErr" => "", "typeOfJobErr" => "", "rankErr" => "", "jTitleErr" => "", "salaryRangeErr" => "", "currencyErr" => "", ); } } ?>
**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