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.

  1. json_encode / json_decode
  2. 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

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -