note 30372 modified in faq.html by felipe
| From: | felipe@php.net | Date: | Tue, 22 Apr 2008 01:05:58 +0000 |
| Subject: | note 30372 modified in faq.html by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-138637@lists.php.net to get a copy of this message | ||
I do not think you are right about not being able to specify something for the value attribute, but
I can see where you would have thought it would fail:
A fair warning about testing to see if a variable exists...
when it comes to strings, the values '' and '0' are interpreted as false when
tested this way...
<?php
if ($string) { ... } //false for $string == '' || $string == '0'
?>
The best practice for testing to see if you received a variable from the form (which in the case of
a checkbox, only happens when it is checked) is to test using this...
<?php
if ( isSet($string) ) { ... } //true if and only if the variable is set
?>
The function tests to see if the variable has been set, regardless of its contents.
By the way, if anyone's curious, when you do make a checkbox without specifying the value
attribute, the value sent from the form for that checkbox becomes 'on'. (That's for
HTML in general, not PHP-specific).
--was--
I do not think you are right about not being able to specify something for the value attribute, but
I can see where you would have thought it would fail:
A fair warning about testing to see if a variable exists...
when it comes to strings, the values '' and '0' are interpreted as false when
tested this way...
<?php
if ($string) { ... } //false for $string == || $string == 0
?>
The best practice for testing to see if you received a variable from the form (which in the case of
a checkbox, only happens when it is checked) is to test using this...
<?php
if ( isSet($string) ) { ... } //true if and only if the variable is set
?>
The function tests to see if the variable has been set, regardless of its contents.
By the way, if anyone's curious, when you do make a checkbox without specifying the value
attribute, the value sent from the form for that checkbox becomes on. (That's for HTML in
general, not PHP-specific).
http://php.net/manual/en/faq.html.php