I'm having a very troubling issue. Maybe I'm just looking over something but I have looked at the code for several hours now, making small adjustments here and there to try to fix this problem. Basically what I am doing is trying to POST the values of this form into my next php file which then records it to a database and mails it to me. I am validating the information submitted on the form in my php executing file. The problem occurs whenever a person does not completely fill out the form and causes it to send back the error messages. My code refills the textboxes and dropdown boxes with the previously information but when it comes to checkboxes it does not at the moment. I took this functionality out for the time being because I found out that when the form is resubmitted the checkboxes are no longer even POSTing the correct values anymore when checked. I have a little test at the bottom of my form to show me the values that my php exec file is sending back (located in the echo $c $obj part) All future submissions after the person submits the form the first time with errors will result in the checkboxes POSTing no value at all even if they are checked. I can't figure out where the value is getting lost...
Code: ###### student-registration.php ######
<html>
<head>
<title>Registration Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.2.1.pack.js"></script>
<script type="text/javascript">
function carryOver(def,obj) {
var control = document.getElementById(obj);
control.value = def;
}
function disChange() {
if(document.getElementById('hidDiagnostic').style.display=='none') {
document.getElementById('hidDiagnostic').style.display = "block";
}else {
document.getElementById('hidDiagnostic').style.display = "none";
}
}
function lookup(inputString) {
if(inputString.length == 0) {
$('#schoolSystems').hide();
} else {
$.post("schoolsystemlookup-exec.php", {ss: ""+inputString+""}, function(data){
if(data.length >0) {
$('#schoolSystems').show();
$('#schoolSystemsList').html(data);
}
});
}
} // lookup
function fill(thisValue) {
$('#ss').val(thisValue);
setTimeout("$('#schoolSystems').hide();", 200);
}
</script>
</head>
<body>
<?php
session_start();
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<h1>Error! Form will not be processed till mistakes are fixed</h1>';
echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<div id="hStudent" style="width:100%; height:50px; background-color:#EAE9E4; color:#FF0000; font-size:40px;">
<b>Basic Student Information</b>
</div>
<form action="studentregistration-exec.php" method="post">
<table>
<tr>
<td>Student First Name:</td>
<td><input type="text" name="stuFName" id="stuFName"/></td>
</tr>
<tr>
<td>Student Last Name:</td>
<td><input type="text" name="stuLName" id="stuLName"/></td>
</tr>
<tr>
<td>Student Grade:</td>
<td><select name="stuGrade" id="stuGrade">
<option value="IP">Infant Program</option>
<option value="PS">Pre-School Program</option>
<option value="KG">K</option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="PG">College</option>
<option value="V">Vocational</option>
<option value="A">Adult Rehabilitation</option>
<option value="OR">Other</option>
</select></td>
</tr>
<tr>
<td>Date of Birth:</td>
<td><select name="bMonth" id="bMonth">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="bDate" id="bDate">
<?php
for($d = 1; $d <= 31; $d++) {
if($d < 10) { echo "<option value='0$d'>0$d</option>";
} else{ echo "<option value='$d'>$d</option>";}
}
?>
</select>
<select name="bYear" id="bYear">
<?php
for($y = date("Y"); $y >= (date("Y")-110); $y--) {
echo "<option value='$y'>$y</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Address #1:</td>
<td><input type="text" name="stuAddOne" id="stuAddOne"/></td>
</tr>
<tr>
<td>Address #2 (optional):</td>
<td><input type="text" name="stuAddTwo" id="stuAddTwo"/></td>
</tr>
<tr>
<td>City/Zip:</td>
<td><input type="text" name="stuCity" id="stuCity"/>
<input type="number" size=3 maxlength=5 name="stuZip" id="stuZip"/></td>
</tr>
</table>
<div id="hSchool" style="width:100%; height:50px; background-color:#EAE9E4; color:#FF0000; font-size:40px;">
<b>School and Material Information</b>
</div>
<table>
<tr>
<td>School System:</td>
<td><input type="text" onkeyup="lookup(this.value);" name="ss" id="ss" />
<div class="suggestionsBox" id="schoolSystems" style="display: none;">
<img src="upArrow.png" style="position: relative; top: -12px; left: 50px" alt="upArrow" />
<div class="suggestionList" id="schoolSystemsList">
</div>
</div></td>
</tr>
<tr>
<td>Transfer Student: </td>
<td><input type="checkbox" value="-1" name="stuTransfer" id="stuTransfer"/></td>
</tr>
<tr>
<td>Primary Reading Material: </td>
<td><select name="readMaterial" id="readMaterial">
<option value="LP">Large Print</option>
<option value="BR">Braille</option>
<option value="AU">Audio</option>
<option value="ET">Electronic Text</option>
</select></td>
</tr>
<tr>
<td>Individual Education Plan or 504 Plan on file?</td>
<td><select name="iep" id="iep">
<option value="-1">Yes</option>
<option value="0">No</option>
</select></td>
</tr>
<tr>
<td>Date Enrolled in School:</td>
<td><select name="enrMonth" id="enrMonth">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="enrDate" id="enrDate">
<?php
for($d = 1; $d <= 31; $d++) {
if($d < 10) { echo "<option value='0$d'>0$d</option>";
} else{ echo "<option value='$d'>$d</option>";}
}
?>
</select>
<select name="enrYear" id="enrYear">
<?php
for($y = date("Y"); $y >= (date("Y")-25); $y--) {
echo "<option value='$y'>$y</option>";
}
?>
</select></td>
</tr>
</table>
<div id="hSchool" style="width:100%; height:50px; background-color:#EAE9E4; color:#FF0000; font-size:40px;">
<b>Eligibility</b>
</div>
<table>
<tr>
<td>Print Disabilities:</td>
</tr>
<tr>
<td /><td>Visual Disability:</td>
<td><input type="checkbox" value="-1" onclick="disChange();" name="disVisual" id="disVisual"/></td>
</tr>
<tr>
<td /><td>Reading Disability:</td>
<td><input type="checkbox" value="-1" name="disReading" id="disReading"/></td>
</tr>
<tr>
<td /><td>Physical Disability:</td>
<td><input type="checkbox" value="-1" name="disPhysical" id="disPhysical"/></td>
</tr>
<tbody id="hidDiagnostic" style="display:none;">
<tr>
<td>Right Eye:</td>
<td>20 / <input type="text" name="eyeRight" id="eyeRight"/></td>
</tr>
<tr>
<td>Left Eye:</td>
<td>20 / <input type="text" name="eyeLeft" id="eyeLeft"/></td>
</tr>
</tbody>
</table>
<div id="hAuthorize" style="width:100%; height:50px; background-color:#EAE9E4; color:#FF0000; font-size:40px;">
<b>Authorizing Information</b>
</div>
I certify that the above information is accurate and fully documented:
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="authName" id="authName"/></td>
</tr>
<tr>
<td>Position/Title:</td>
<td><input type="text" name="authTitle" id="authTitle"/></td>
</tr>
<tr>
<td>Phone Number:</td>
<td>(<input type="text" size=1 maxlength=3 name="authArea" id="authArea"/>) <input type="text" size=1 maxlength=3 name="authPhoneOne" id="authPhoneOne"/> - <input type="text" size=2 maxlength=4 name="authPhoneTwo" id="authPhoneTwo"/></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="authEmail" id="authEmail"/></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="authAddress" id="authAddress"/></td>
</tr>
<tr>
<td>City/Zip:</td>
<td><input type="text" name="authCity" id="authCity"/> <input type="number" size=3 maxlength=5 name="authZip" id="authZip"/></td>
</tr>
</table>
<input type="submit" value="Submit"/>
</form>
<?php
if( isset($_SESSION['FORM_ARR']) && is_array($_SESSION['FORM_ARR']) && count($_SESSION['FORM_ARR']) >0 ) {
$field_arr = array();
$field_arr[0]="stuFName";
$field_arr[1]="stuLName";
$field_arr[2]="stuGrade";
$field_arr[3]="bMonth";
$field_arr[4]="bDate";
$field_arr[5]="bYear";
$field_arr[6]="stuAddOne";
$field_arr[7]="stuAddTwo";
$field_arr[8]="stuCity";
$field_arr[9]="stuZip";
$field_arr[10]="ss";
$field_arr[11]="stuTransfer";
$field_arr[12]="readMaterial";
$field_arr[13]="iep";
$field_arr[14]="enrMonth";
$field_arr[15]="enrDate";
$field_arr[16]="enrYear";
$field_arr[17]="disVisual";
$field_arr[18]="disReading";
$field_arr[19]="disPhysical";
$field_arr[20]="eyeRight";
$field_arr[21]="eyeLeft";
$field_arr[22]="authName";
$field_arr[23]="authTitle";
$field_arr[24]="authArea";
$field_arr[25]="authPhoneOne";
$field_arr[26]="authPhoneTwo";
$field_arr[27]="authEmail";
$field_arr[28]="authAddress";
$field_arr[29]="authCity";
$field_arr[30]="authZip";
$c=0;
foreach($_SESSION['FORM_ARR'] as $obj) {
echo "<SCRIPT type='text/javascript'>carryOver('" . $obj . "','" . $field_arr[$c] . "');</SCRIPT>";
echo $c . " - " . $obj . "
";
$c++;
}
unset($_SESSION['FORM_ARR']);
}
?>
</body>
</html>Code: ##### studentregistration-exec.php #####
<?php
function session_restart()
{
if (session_name()=='') {
// Session not started yet
session_start();
}
else {
// Session was started, so destroy
session_destroy();
// But we do want a session started for the next request
session_start();
session_regenerate_id();
// PHP < 4.3.3, since it does not put
setcookie(session_name(), session_id());
}
}
//Start session
//session_start();
//Array to store validation errors
$errmsg_arr = array();
//Array to store previous form entries
$form_arr = array();
//Validation error flag
$errflag = false;
require_once('config.php');
$link = mysql_connect(DB_HOST, DBA_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DBA_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$form_arr[0] = $stuFName = clean($_POST['stuFName']);
$form_arr[1] = $stuLName = clean($_POST['stuLName']);
$form_arr[2] = $stuGrade = clean($_POST['stuGrade']);
$form_arr[3] = $bMonth = clean($_POST['bMonth']);
$form_arr[4] = $bDate = clean($_POST['bDate']);
$form_arr[5] = $bYear = clean(
insert/update functions for mysql, what do you think?
I am working on two really simple functions that automatically generate (and execute) insert and update mysql queries and I have some questions:Can there be any problems later on if functions treat
simplexml_load_file and rss problem
Hi,I have a problem parsing an rss feed using simplexml_load_file - this is strange as i have used the same code to parse literally 1000s of different feeds in the past, and even stranger in that if i
Slow data retrieval which requires improvement..please help
I am working on a Help Desk Ticketing system and have a page called MY TICKETS which shows all tickets in grids. the problem is that the number of records are around 30 to 40 but there is a lag
Php If in MySql query (hiding labels if a field is empty)
Okay, I've been trying to do this for a while, and I'm finally going to ask for help so I can get the simple answer and feel like an idoit .Anyway, I'm building a dynamic driver profile page for my
EXplanation help
Hey all,I am still fairly new to PHP programming and I am trying to put together a page where you select search terms from a drop down menu and it keeps the menu at your search choice in the menu
Problem with variable declaration in switch statement
Hello, I am having some trouble assigning a value to a variable inside a switch statement. What I am trying to do here is trip an error if the user has already added an item in the shopping cart.
Auto fill in input value based on User_ID
Hello,I'm looking form some input on the following problem.User loads page -> page loads values from database and inputs them in boxes -> user edits input boxes -> new values
quotes changing
hi allin my contentopening quotes " changes to “close quotes " changes to �what should i use.example :Code: sams’s “whip lashâ€
Setting a default timezone?
I have read about how to change the timezone in PHPMYADMIN, but it changes back, it doesn't STAY there.If thats not possible, if I had..;$time = date("d-m-Y H-i-s" time());or.. if I had
Code Review - SQL and Insertion Attacks (Warning: Not for Newbs)
Hey guys,Its been a while, I know. Use to love coming here to answer peoples questions, but work and school have been keeping me too busy but do anything but lurk. I usually write all my code/apps by