I have form like this. I want add dynamic multi group fileds (user create fields groups if needs)...
currently I do it this way:
<form>
<!-- group fileds 1 -->
<input type="text" id="input1">
<select id="slect1"></select/>
<!-- group fileds 2 -->
<input type="text" id="input2">
<select id="select2"></select/>
.
.
.
<!-- group fileds n -->
<input type="text" id="inputn">
<select id="selectn"></select/>
</form>
But manage is hard,specially in php server.
can you recommend me a better way?
for example this is my idia:
I create one hidden input.
read input&select via jquery,convert it to a long json string,and write it to hidden input.
then in server side, I only read that hidden input and parse json.
it seems complex
how do you manage these type of forms?
You can use indexes after inputs' names. This work will give you an array at the server side, in $_POST['input']
and $_POST['select']
:
<form method='post' action='sth.php'>
<!-- group fileds 1 -->
<input type="text" name="input[0]">
<select name="select[0]"></select/>
<!-- group fileds 2 -->
<input type="text" name="input[1]">
<select name="select[1]"></select/>
<!-- group fileds 3 -->
<input type="text" name="input[2]">
<select name="select[2]"></select/>
</form>