E
E
excalibur2013-02-09 09:45:37
PHP
excalibur, 2013-02-09 09:45:37

Saving multiple form fields with the same name

We have this form:

<form name="myForm">
<textarea name="description[]"></textarea>
<textarea name="description[]"></textarea>
<textarea name="description[]"></textarea>
<textarea name="description[]"></textarea>
<textarea name="description[]"></textarea>
</form>


Click "Save" and get an array that we save in the database. Each "description" element has a unique "id" in the database. Those. database structure:

id | description
1 | Text from "textarea"
2 | More text from "textarea"
3 | Text with the following "textarea"
4 | etc.

In the “myForm” form, the “description” fields are both edited by existing ones and new ones are dynamically added.

How to identify the description fields so that when saving the form it is clear to which id in the database the field belongs or to find out that the field is new, i.e. dynamically created.

I don't really like the way I know, that's why I'm asking a question.

Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alexhemp, 2013-02-09
@alexhemp

<form name="myForm">
<textarea name="description[1]"></textarea>
<textarea name="description[2]"></textarea>
<textarea name="description[3]"></textarea>
<textarea name="description[4]"></textarea>
<textarea name="new[]"></textarea>
</form>

Those from the database - specify existing IDs as an index, and new ones - with separate names.

J
Jonh Doe, 2013-02-09
@CodeByZen

If the form is filled out by different users, then I suggest adding at least the user ID and the time of adding to the table. This way we know who owns which records and can see which user records were new relative to the rest.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question