Issue
I use PHP to get radio button values from an HTML page. My HTML looks like this:
<input type="radio" name="1.1" value="yes">
<input type="radio" name="1.1" value="no">
<input type="radio" name="1" value="yes">
<input type="radio" name="1" value="no">
The result is that $_POST['1'] returns a value, but $_POST['1.1'] returns nothing. I checked the HTML 4 specifications, say value for the name attribute only starts with a letter, but 1 is not a letter. How come it gets returned while 1.1 does not? Or is there some other magic happening here? I use the latest version of Chrome.
Solution
By HTML rules, the name
attribute may have any value: it is declared with CDATA type. Do not confuse this attribute with the references to attributes declared as having NAME type. See 17.4 The INPUT element, name = cdata [CI].
In the use of $POST[...]
in PHP, you need to note this PHP rule: “Dots and spaces in variable names are converted to underscores. For example <input name="a.b" />
becomes $_REQUEST["a_b"]
.” See Variables From External Sources.
So $_POST['1']
should work as is and does work, but instead of $_POST['1.1']
you need to write $_POST['1_1']
.
Answered By - Jukka K. Korpela
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.