please help me with a simple PHP doubt.
I have a simple form:
< form action=”foo” >
< label >Person:< /label >
< input type=”text” id=”name” >
< input type=”text” id=”last_name” >
< a href=”javascript:addmore();”>Add More
< /form >
Every time the user clicks Add More two new input fields will be dynamically created using jQuery. This can be done several times in a same form.
< form action=”foo” >
< label>Person:< /label >
< input type=”text” id=”name” >
< input type=”text” id=”last_name” >
< input type=”text” id=”name_2″ >
< input type=”text” id=”last_name_2″ >
< a href=”javascript:addmore();”>Add More
< input type=”sbumit” >
< /form >
Each pair (name and last_name) should create on record in my db.
Two Questions:
1) What is the best option for input id? Appending a counter is the best option?
2) How can I handle it in the backend using php?
Let me know if you need more info.
Thanks in advance.
Some code got lost in your post. And your form needs a method, probably POST.
Still, the best option would be creating inputs with the same name ending with []:
PHP will see it as an array with such elements:
That is if you submit the form once for all the records. If you want to immediately save every record, google for ajax tutorials.