Need help with saving form values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fondowe
Forum Newbie
Posts: 1
Joined: Fri Apr 15, 2011 2:40 am

Need help with saving form values

Post 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.
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Need help with saving form values

Post 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++){

}
Post Reply