-1

I am attempting to get information from an HTML form to a PHP script. The catch is that I need to be able to add/subtract rows from the form, and dynamically adjust the data received by the PHP form. Each row of the form has only one text box for data.

For example, I need to enter three users in the form. One row is displayed by default. I'll hit the "add row" button twice, so three boxes are there, then I'll enter User 1, User 2, and User 3. All three names need to be passed to the PHP form, which parses all 3 names and does its thing.

I can probably come up with the PHP logic (although any help would be appreciated), but I don't know how to dynamically post the HTML form to the PHP script or how to add/subtract rows from the form itself.

vaindil
  • 7,536
  • 21
  • 68
  • 127
  • Try the following answer to get started on the basics of AJAX with PHP: http://stackoverflow.com/a/5004276/212700 – leepowers Dec 20 '12 at 01:13
  • Please do some search, this has been asked and explained, How-To'ed, Blog-Posted, jQuery-Jodled from here to eastern Mississippi. And you didn't come up with a single line of code nor an idea? – hakre Dec 20 '12 at 01:46
  • I did search quite extensively before posting for assistance. I know it's been covered, but I was having difficulty applying things to my system. – vaindil Dec 20 '12 at 01:59

1 Answers1

2

If you have each row of users use an array for the name rather than a specific name you could go through the array in the PHP page using a foreach.

<div>
    <input type="text" name="users[*row number*][name]" value="" />
</div>

In the PHP file the users would be accessible using

foreach ($_POST['users'] as $row => $value) {
    // name would be $value['name']
}

Edit:

The form can be created using the same sort of format as http://jsfiddle.net/gM8MM/

Then you can access that data using somthing like http://pastebin.com/n6sa6kpJ

qooplmao
  • 17,622
  • 2
  • 44
  • 69