I design a form that contains dynamic contents.
For example,
The form has a textfield for Paper_Name and a textfield for Paper_Link.
The user can add up to ten paper names and paper links.
The id for each paper name and paper link is as follows:
papername01, paperlink01, …, papername10, paperlink10.
Those ids are dynamically created by JavaScript. In other words, if the user doesn’t click Add Paper button and submit the form, the only field that will be received by the server is paperlink01, and papername01.
Now, the question what is a better practice to design the server PHP script to handle those submitted form content.
-
Use Ajax form plugin?
-
Use regular form submission and iterate through all variables and see whether any of them is set?
-
use JSON data format?
Yes, the question is related to both server and client. I would like to know the best practice and change my client accordingly.
Please help and thank you
The form design looks like the following:
<div id="divDummy001">
<div id="paperTitle001Fld">
<label for="papertitle001">Title of Paper 001</label>
<div>
<input type="text" size="16" value="" id="papertitle001" name="papertitle001"/>
</div>
</div>
<div id="paperURL001Fld">
<label for="paperurl001">Paper Link 001</label>
<div>
<input type="text" size="96" value="" id="paperurl001" name="paperurl001"/>
</div>
</div>
</div>
When the user clicks Add button, a new div will be created with the only difference is that the ID will be increased by 1.
Use arrays. Create textfields with names like
papername[1], papername[2]then they’ll appear as arrays in PHP script.