Accessing multiple cloned fields from PHP
I have a form which has the ability to copy a row of several fields using jquery - my questi开发者_如何学运维on is how do I access these form values in the target php page?
Any code, by chance? Anyway, you can make it add a name to the new field with square braces, so ti will be accessed as an array, like it happens with multiselect checkboxes
es: new field 1 <input type="text" name="added[]" value="">
new field 2 <input type="text" name="added[]" value="">
and so on...
Then you have everythin in the $_POST['added'] array
If they have the same 'name' attribute value, change that value to 'name[]' so that they look like
<input type="text" name="name[]" />
<input type="text" name="name[]" />
<input type="text" name="name[]" />
<input type="text" name="name[]" />
//etc...
and you should be able to access them by using:
$value = $_POST['name'][0];
where 0 is the index of the field, IE, the first field is 0, second is 1...
It is easier to access these using a for loop
for($i = 0; $i < count($_POST['name']; $i++)
// actions with $_POST['name'][$i]
or a foreach loop.
foreach($_POST['name'] as $value)
// actions with $value
Depends on how jquery is adding them. Do the following on the called page and see how they're being passed through.
var_dump( $_POST ); // Or maybe $_GET
精彩评论