Jump to content

creating and passing an array from input tag to php?


darksniperx

Recommended Posts

What I would like to do this. I need to create a way to generate html code with a button click. For example, I would like to create a list of people's name with their emails and remove any of them at any time.

 

part of the code would look something like this:

<a href="javascript:add();">Add Field</a>

<div id='people'>
Name:<input type='text' name='name[]' /> Email:<input type='text' name='email[]' /><a href="javascript:remove();">Remove Field</a><br/>

</div>

When ever someone clicks add field, the code adds the following line inside div tag

When ever someone clicks remove field, the code will remove that its line from div tag.

 

the second part, is that I would like to pass the array to of name and email to php and work with them

foreach($_POST['name'] as $name, $_POST['email'] as $email)
{
// do the following
}

and also that they would be synchronized together, that email would belong to the to its name and not to any other onces in the array.

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.