Recently while working with checkbox, I've to go through following test code:
<?php if ( isset( $_POST['myname'] ) ) {
$myvalue = $_POST['myname'];
echo $myvalue; } ?>
<form method="post">
<input type="checkbox" name="myname" />
<input type="submit" name="send" /></form>
So, what output I got after form submission is when checkbox is checked it prints 'on' else nothing (if value is not provided on checkbox). And isn't it supposed to print 1(true) on checking the checkbox. What that 'on' means in PHP?
If you don't provide value
attribute for checkbox, it's value will be on
With
<input type="checkbox" name="myname" />
$_POST['myname']
value is on
With
<input type="checkbox" name="myname" value="1" />
$_POST['myname']
value is 1
In both cases when checkbox is unchecked , it doesn't present in $_POST
(not set)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.