0

I have created an online form which allows a user to input the number of different products they want to return & then enter details about that product.

It's never known how many form input fields will be passed to a PHP script to process the form as it depends on the number of products the user wants to return & store the results into an MySQL database.

The way I was thinking of passing all form fields to the PHP script was by looping through the number of form fields via JavaScript & storing that figure in a hidden form input field then passing that to the PHP script & using that number to set-up a loop to iterate through the inputs.

I hope this makes sense & any advice would be appreciated.

Dan
  • 9,391
  • 5
  • 41
  • 73
Lee W
  • 9
  • Is [this](http://stackoverflow.com/questions/3314567/how-to-get-form-input-array-into-php-array) what you're trying to do? – Dan Aug 25 '14 at 17:49
  • Sounds like a sound solution. Go ahead and build it. – GolezTrol Aug 25 '14 at 17:49
  • The way I would handle this is probably set a variable in front of the field name, example product_ID#_variable. Loop through your $_POST and locate each individual product_, then parse out the ID# and the variable. Determine what's filled out and what isn't. Send back errors if the user is missing information. – ChrisG Aug 25 '14 at 17:49
  • @ChrisG easier to just name every input like : `name="myform[txt_name]"` and so on. Then U don't need to do the scraping in the `$_POST` – DarkBee Aug 25 '14 at 17:53
  • @DarkBee that works as well. I just like parsing out everything in $_POST to be extremely strict with what information is posted. – ChrisG Aug 25 '14 at 17:54
  • Is it okay to have multiple form fields using the same name & storing the value of each into an array then passing that to a PHP variable to loop through? – Lee W Aug 26 '14 at 12:53
  • I don't see why not, I always do this with checkboxes as well – DarkBee Aug 26 '14 at 20:20

0 Answers0