I'm using a dynamicaly generated form, depending on user input its asking for personal information from 1 up to 9 people. As a backend scripting language i'm using php.
Im using a JavaScript to validate the form, this script looks like this:
function verify(f){
var msg;
var empty_fields = "";
for (var i = 0; i < f.length; i++){
var e = f.elements[i];
if(e.mandatory){
if((e.value == null) || (e.value == ""){
empty_fields += "\n- " + e.name;
continue;
}
}
}
To call this function -
<form onsumbit="lastname.madatory = true;verify(this)">
(Feel free to use .. its from the O'Reilly Rhino Book)
For 9 people i'm using the field lastname 9 different times, each time with the exact same name. Like so
--
Person 1 <input type="tekst" name="lastname">
Person 2 <input type="tekst" name="lastname">
--
This is actually no problem, the 9 different instances are stored in an array and all of them are traversed and checked seperately.
Now for my problem:
When the form is sent Php overwrites the first occurence of lastname with a later one. I end up with only one lastname where i need more.
The solution to this problem is to name the fields lastname[]. Php now automatically creates an array by the name of lastname containing all lastnames when the form is sent.
But when i do this the validation script doesn't work anymore, it might have something to do with the brackets but i'm not sure. I'm stuck between a rock and a hard place as the song goes.
Does anybody know a solution to this problem, preferably in JavaScript, it would be a real hassle to fix it in Php.
Thanks for even reading the whole thing
Ruben


The solution i used is somewhat different tho. The problem was in a different part of my script .. i was looking at the wrong thing. I actually use a function to initialize the fields i want to be mandatory