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.

 

original post: http://www.phpfreaks.com/forums/index.php/topic,169355.0.html

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.