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(
Redistributing dependent dlls
Hai all ,I have created an application in VC++ using VS2008 in a development machine which runs on Vista, now i need to run that application in a target machine which runs on windows XP SP2 which does
php forms and database navigatio
Hello,I'm new to php and i'd like to post the following.I have written code to get records from a DB and i need one record at a time to be filled in a form i created. Then the next record should be
Call to undefined function mysql_fetch_accoc()
New to php/mysql coding. What's wrong with this sequence, or am I just not seeing to obvious?Getting, "Call to undefined function mysql_fetch_accoc()" at line n, whereline n is referring to
Character Set Setup
Whats the best character set to use if you want every character to work, and also how do you make your files, mysql stuff, and all that set for the best character type..... got a check list i can
Preg_match with an array
is there an away to use preg_match with an array?i want to check a string with an array to see if it contains badwords however i get an error saying string expect it got an array, which i know.
multipart emiail forms
Hi All, I am new to the boards and I've been working on a form (which is rather massive, imo) and i've been looking online at other peoples php examples for multipart emails. The code i am using /
A href problem under php
Hello...I tried to explain the issue in an earlier post.. but was not clear enough....So let me try again:I think that the problem happens in Loops (while).When I add a simple html a href (link)...
mail() says sent but no email received
My code is quite simple:Code: <?php$to = "Ty44ler@yahoo.com";$subject = "Test mail";$message = "Hey, I just wanted to see if the script worked.";$from =
Multiple while loops
I have several DB queries that I know should be returning results and aren't. I have a feeling it has to do with the several while loops that should be outputting the data. One more issue is that
Preserving user-entered linebreaks
Hi, I'm building a web 2.0 thingy from scratch and I wanna display text which users input. It's all good so far, except that all the linebreaks are destroyed, so no matter how carefully they insert