rondog Posted September 26, 2010 Share Posted September 26, 2010 Hey guys I have a form, but on the form you are able to add extra fields. My question is how would I POST those extra fields? The way I always do it is $_POST['field_name'], however how would I know if theyve added new fields. Here is an image of what the field looks like so you get a better idea of what im talking about. Quote Link to comment https://forums.phpfreaks.com/topic/214482-post-additional-fields/ Share on other sites More sharing options...
plznty Posted September 26, 2010 Share Posted September 26, 2010 Post on the code and we'll add fixes. It is hard to explain something by not knowing the background. Quote Link to comment https://forums.phpfreaks.com/topic/214482-post-additional-fields/#findComment-1116088 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2010 Share Posted September 26, 2010 If you use a HTML array name as the field name="some_name[]", you can just iterate over the resulting $_POST['some_name'][] array using php's array functions, such as foreach() and/or count() Ref: http://www.php.net/manual/en/faq.html.php#faq.html.arrays Quote Link to comment https://forums.phpfreaks.com/topic/214482-post-additional-fields/#findComment-1116089 Share on other sites More sharing options...
litebearer Posted September 26, 2010 Share Posted September 26, 2010 you could count the elements in the $_POST array - ie if form initially starts with 4 fields and the count of $_POST array is 8 then you know 4 fields have been added Quote Link to comment https://forums.phpfreaks.com/topic/214482-post-additional-fields/#findComment-1116090 Share on other sites More sharing options...
rondog Posted September 26, 2010 Author Share Posted September 26, 2010 If you use a HTML array name as the field name="some_name[]", you can just iterate over the resulting $_POST['some_name'][] array using php's array functions, such as foreach() and/or count() Ref: http://www.php.net/manual/en/faq.html.php#faq.html.arrays This looks like exactly what I need. Thanks for the ideas guys. Quote Link to comment https://forums.phpfreaks.com/topic/214482-post-additional-fields/#findComment-1116092 Share on other sites More sharing options...
rondog Posted September 27, 2010 Author Share Posted September 27, 2010 Hey, another questions regarding this. Why does this for loop not work on the other array fields? //--> CONTROLLERS $system_controllers_qty = $_POST['system_controllers_qty']; $system_controllers_make = $_POST['system_controllers_make']; $system_controllers_model = $_POST['system_controllers_model']; $system_controllers_serial_no = $_POST['system_controllers_serial_no']; for ($i = 0; $i < count($system_controllers_qty); $i++) { echo "qty " . $system_controllers_qty[$i] . "<br/"; echo "make " . $system_controllers_make[$i] . "<br/"; echo "model " . $system_controllers_model[$i] . "<br/"; echo "serial_no " . $system_controllers_serial_no[$i] . "<br/"; } This only outputs the $system_controllers_qty, yet if i do a print_r on each, they all contain data. In theory, they will all contain data even if its an empty string. Quote Link to comment https://forums.phpfreaks.com/topic/214482-post-additional-fields/#findComment-1116148 Share on other sites More sharing options...
rondog Posted September 27, 2010 Author Share Posted September 27, 2010 never mind, i am a retard...I didn't close my <br/> tag.. Quote Link to comment https://forums.phpfreaks.com/topic/214482-post-additional-fields/#findComment-1116150 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.