Page 1 of 1

Need help with saving form values

Posted: Fri Apr 15, 2011 2:49 am
by fondowe
I have x number of input fields in my form like this:
<input type="text" name="name[]" value="" />
<input type="text" name="name[]" value="" />

User can add a new input field with 'Add new input field' button.

Im validating my form so my question is how to echo the values user have entered
in the input fields when the user have submitted the form and
error appears, since the values are in array.

I could do this:

Code: Select all

value=" <?php echo $_POST[name][1]; "
But since i dont know how many inputs fields there will be, i need to loop them
throught somehow.

Re: Need help with saving form values

Posted: Fri Apr 15, 2011 3:16 am
by Weiry
you could either use a foreach or for loop.

Code: Select all

foreach($_POST['name'] as $value){

}

for($i = 0; $i < count($_POST['name']); $i++){

}