html - Is this the correct way to check in PHP that a checkbox is checked? -
i have code check tos checkbox checked:
if (!isset($_post['tosagree'])) {//if user did not agree tos $errors[] = '<span>please agree terms of service.<span>'; }
for reason allowing me register code there. weird thing if other field not field , field not checked print error, if problem allows user register.
update: seems problem weird in code. if feel looking through 217 lines of code here code: http://pastebin.com/ykerypef
whether !isset($_post['tosagree'])
enough depends on browser.
to safe, set value
attribute of checkbox. then, check if value present:
<input type='checkbox' value='agreed'/>
then this:
if (!isset($_post['tosagree']) || $_post['tosagree'] != "agreed" ) { $errors[] = '<span>please agree terms of service.<span>'; }
also, when value
attribute not explicitly specified, browsers set value
on
when checked.
edit
ok, know what's happening. in php code, have block:
if (!isset($_post['tosagree']) || $_post['tosagree'] != "agreed") {//if user did not agree tos $errors[] = '<span>please agree terms of service.<span>'; }
then later have line:
if ($un && $e && $p && $ic) { //if there no errors
the problem don't have flag when tos checkbox isn't checked. error can't printed because in if
statement have call exit()
.
Comments
Post a Comment