php - Posting an array() -
if in form post hidden field this:
<input type="hidden" name="userarr" value="array([0] => 13 [1] => 10 [2] => 12 [3] => 9 [4] => 14 [5] => 11)">
do keep benefit of array?
do need call input name field userarr
or userarr[]
?
solution array exists:
foreach ($userarr $value) { echo '<input type="hidden" name="userarr[]" value="'.$value.'">'; }
you'd better like, "user input can never trusted! not when it's hidden!"
<input type="hidden" name="userarr" value="<?= htmlentities(json_encode(array(10, 20, 30), ent_noquotes); ?>">
and server side keep array:
$arr = json_decode(html_entity_decode($_post['userarr'], ent_noquotes));
the value using handled normal string, can't convert array. there several ways encode , decode it. examples below. have encode quotes not cause problems.
- json_encode / json_decode
- serialize / unserialize
if call input []
can post array server, when got multiple input fields same name. example, got 5 checkboxes if people want receive mail different subject. subject can have same input name []
got dynamically handled instead of giving each input different name.
Comments
Post a Comment