well, I don't think I've explained myself very well and so apologize. On the client side the form is done fairly well. The main reason I'm stumped is because I've nver used loops and so don't know how to validate this form. What I was trying to explain is that I am dynamically creating form fields in div's. Each form field is named dynamically by this script.
function addFlights() {
var ni = document.getElementById('flight');
var numi = document.getElementById('flightValue');
var num = (document.getElementById('flightValue').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = 'flight '+num+'';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = '<div class="add"><h3>Flight '+num+'</h3><div class="r"><label for="from'+num+'">Departure City: </label>
<input type="text" name="from[]" id="from'+num+'" size="10" maxlength="30" /></div>
<div class="r"><label for="to'+num+'">Arrival City: </label><input type="text" name="to'+num+'" id="to'+num+'" size="10" maxlength="30" /></div>
<div class="r"><label for="date'+num+'">Departure Date: </label><input type="text" name="date'+num+'" id="date'+num+'" size="10" maxlength="10" /></div></div>';
ni.appendChild(newdiv);
}
This script adds the extra form fields. When it does so each input's name is something like name="to'+num+'" which would be "name1" for the first set and "name2" for the second and so on. Am I making sense yet?
So back to the validation. How can I display the form results back to the user after I validate it? This is what I have to display the results to the user so far. What I'm trying to do display the results to the user after validating them but I don't know how to do that when the number of the dynamically added divs is unknown to me. In reality the user will never add more than 5, but I don't want to have to write the following code out 5 times just in case because there are 5 areas in the form like this.
if(!$error){ //check the for any errors that occured
echo '<div id="success"><h2 class="success">The Form was submitted successfully!</h2>
<div class="row">
<span class="label">Departure City:</span>
<span class="form">'.stripslashes($from[$i]).'</span>
</div>
<div class="row">
<span class="label">Arrival City:</span>
<span class="form">'.stripslashes($to1).'</span>
</div>
<div class="row">
<span class="label">Departure Date:</span>
<span class="form">'.$date1.'</span>
</div>
<div class="row">
<span class="label">Preferred Time:</span>
<span class="form">'.$time1.'</span>
</div>
} else {
echo "<div id=\"error\"><h2 class=\"summary\">The following errors need to be fixed:</h2><ul> ";