I have a lot of fieldset in my php file, most of them came from the database that are not processed yet..
I don't know how many fieldset will go so the name of the inputs have numbers, the numbers are the id of the id field in my table
<form action="" method="post">
<ul>
<fieldset>
<li class="span-24 " style="height:100px;">
<div class="span-5 border">
<a href="a">Lorem Ipsum</a>
</div>
<div class="span-5 border">
<input type="text" name="1 company" value="" placeholder="Enter the company name.." />
</div>
<div class="span-5 border">
<input type="text" name="1 website" value="" placeholder="Enter the website" />
</div>
<select name="1 category" class=span-4>
<option value="Lorem1">Lorem </option>
<option value="Lorem2">Lorem </option>
<option value="Lorem3">Lorem ipsum </option>
<option value="Lorem4">Lorem ipsum </option>
<option value="Lorem5">Lorem ipsum </option>
<option value="Lorem6">Lorem ipsum </option>
<option value="Lorem7">Lorem ipsum </option>
</select>
<select name="1 address[]" multiple="multiple">
<option value="Lorem ipsum 1">Lorem ipsum </option>
<option value="Lorem ipsum 2" selected="selected">Lorem ipsum </option>
<option value="Lorem ipsum 3">Lorem ipsum </option>
<option value="Lorem ipsum 4" selected="selected">Lorem ipsum </option>
<option value="Lorem ipsum 5">Lorem ipsum </option>
开发者_开发技巧 </select>
</li>
</fieldset>
<fieldset>
<li class="span-24 " style="height:100px;">
<div class="span-5 border">
<a href="a">Lorem Ipsum</a>
</div>
<div class="span-5 border">
<input type="text" name="2 company" value="" placeholder="Enter the company name.." />
</div>
<div class="span-5 border">
<input type="text" name="2 website" value="" placeholder="Enter the website" />
</div>
<select name="2 category" class=span-4>
<option value="Lorem1">Lorem </option>
<option value="Lorem2">Lorem </option>
<option value="Lorem3">Lorem ipsum </option>
<option value="Lorem4">Lorem ipsum </option>
<option value="Lorem5">Lorem ipsum </option>
<option value="Lorem6">Lorem ipsum </option>
<option value="Lorem7">Lorem ipsum </option>
</select>
<select name="2 address[]" multiple="multiple">
<option value="Lorem ipsum 1">Lorem ipsum </option>
<option value="Lorem ipsum 2" selected="selected">Lorem ipsum </option>
<option value="Lorem ipsum 3">Lorem ipsum </option>
<option value="Lorem ipsum 4" selected="selected">Lorem ipsum </option>
<option value="Lorem ipsum 5">Lorem ipsum </option>
</select>
</li>
</fieldset>
<input type="submit" name="submit" value="Submit" />
</form>
But when I access the $_POST, I have no way to group the data properly because the data are not grouped together..
Is there a way to group each fieldset so that I can know where this data will be inserted?
The $_POST names are derived from the name=
attributes of the individual input elements. Fieldsets are ignored. You will need to give every element a unique name
attribute.
If you need to deal with a variable number of elements, use a naming prefix. Then the individual elements can be named like elem1
, elem2
, elem3
, etc. This way it won't matter how many records you have in the database.
Well, your select names shouldn't have any spaces. And view $_POST['category'] will give you Lorem1. You would use $_POST['address'] to loop through those values... The "1 " is probably throwing your code off.
精彩评论