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
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

 

This looks like exactly what I need. Thanks for the ideas guys.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.