Jump to content

POST additional fields


rondog

Recommended Posts

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.

 

postq.jpg

Link to comment
https://forums.phpfreaks.com/topic/214482-post-additional-fields/
Share on other sites

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.