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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -