two options:
- name the input field arrays answer_1, answer_2 etc. this can be treated as a pseudo-array by php, i.e. you can process it in a loop as if it were an array. use variable variables:
HTML FORM:
<input type=hidden name=total value=2>
(in this case you must tell the script that you post to, how many fields it shall process, as count() only works on arrays)
<input type=text name=answer_1>
<input type=text name=answer_2>
do the validity check with javascript. javascript has no problem with names like "answer_1".
then, in PHP:
$answer = array();
for($i=1; $i<=$total; $i++)
{
array_push($answer, ${"answer_".$i});
}
now you've got your array answer[].
- in order to be independant from (client-side) javascript, you could do the validity check server-side, i.e. via PHP. (I prefer this!)
HTH