Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an HTML dropdown menu that looks like this

<select name='not working random test!'>
<option value='0'>Select quantity:</option>
<option value='1'>1 room</option>
<option value='2'>2 rooms</option>
</select>

Is it even possible that, if I'm var_dumping $_POST, I see something like this?

["not_working_random_test!"]=>
string(1) "1"

This is causing some troubles with my engine: I expect the name I specify for the select to be the same. Why is this not happening?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
333 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is standard PHP behaviour. From the documentation:

Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"].


The full list of field-name characters that PHP converts to _ (underscore) is the following (not just dot):

  • chr(32) (space)
  • chr(46) . (dot)
  • chr(91) [ (open square bracket)
  • chr(128) - chr(159) (various)

If both an open and a closing square bracket are present, they are not converted but the $_POST element becomes an array element.

<input name='hor[se'>
<input name='hor[se]'>

will become:

$_POST['hor_se'];
$_POST['hor']['se'];

::Reference


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...