I have an "apply for a job" form that includes a bunch of checkboxes -- "Check the jobs that you would like to apply for".... The checkboxes get their name/value from a database.
I can get the checkboxes to display correctly. What I can't do is get them to stay checked/unchecked once someone has submitted the form and then gets an error message that takes them back to the form. I have looked around this forum and several others and found code that should work -- but it doesn't. Here's the code I'm using:
// Connect to the dbase and get the job data...
// Use a while loop to get all job data
while ($row = mysql_fetch_array($result)) {
$job_id = $row["job_id"];
$job_title = $row['job_title'];
// Display checkboxes using the job data
if ($_HTTP_POST_VARS['job[$job_id]'] == '$job_title') {
echo ("<input type=\"checkbox\" name=\"job[$job_id]\" value=\"$job_title\" checked> $job_title<br>\n");
} else {
echo ("<input type=\"checkbox\" name=\"job[$job_id]\" value=\"$job_title\"> $job_title<br>\n");
}
} // end while loop
I've tried this using just $POST in place of $HTTP_POST_VARS. I've also tried this using isset($_POST) and other variations (eg., if (!isset...). The form comes back with all of the job titles and checkboxes showing - just not with any checked that may have been checked and then submitted.
I've got some non-dynamically generated checkboxes in this form and am able to get those to display as checked/unchecked with no problem. Here's example code for that:
if ($full_time_work_wanted == 1) {
echo ("<input type=checkbox name=full_time_work_wanted value=1 checked> Full Time<br>");
} else {
echo ("<input type=checkbox name=full_time_work_wanted value=1> Full Time<br>");
}
In the end, we simply are e-mailing the form input to someone.
So no need to save anything to the database or the like. Except for this dynamically generated checkbox part of the form, the application is pretty straightforward.
Any help - very appreciated!