jj20051 Posted September 11, 2010 Share Posted September 11, 2010 I'm building a form using ajax that will allow users to add additional rows to their submissions. The problem however is getting PHP to recognize those variables. So that if the user submits 5 rows, it reads and creates a variable for all 5. I'm pretty sure that doing this will involve some form of while() processing and a total row count, but I'm unsure how to name the variables on the form end and how to receive those into PHP without the script erroring out. Suggestions? I was thinking something along the lines of naming each variable something like "number_title" or as an example "5_title." Then using a while function to pull the data from $_POST[$number.'_title']; or something similar, but I'm unsure if that method would even work. Quote Link to comment https://forums.phpfreaks.com/topic/213135-unlimited-variables-using-_post/ Share on other sites More sharing options...
jcbones Posted September 11, 2010 Share Posted September 11, 2010 AJAX is not PHP, so the data manipulation is no different than any other PHP script, it is just that the data is sent to the server via javascript. Make sure you set the POST, or GET properties in your javascript function correctly, and you should be able to retrieve those variables just like any other PHP script. Quote Link to comment https://forums.phpfreaks.com/topic/213135-unlimited-variables-using-_post/#findComment-1109899 Share on other sites More sharing options...
ram4nd Posted September 11, 2010 Share Posted September 11, 2010 make hidden field that holds the number of fields... Nice tutorial by me: http://www.browse-tutorials.net/tutorial/add-form-fields Quote Link to comment https://forums.phpfreaks.com/topic/213135-unlimited-variables-using-_post/#findComment-1109958 Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2010 Share Posted September 11, 2010 If you use a html array, you don't need to keep track of how many fields there are - http://www.php.net/manual/en/faq.html.php#faq.html.arrays Quote Link to comment https://forums.phpfreaks.com/topic/213135-unlimited-variables-using-_post/#findComment-1109960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.