When I submit form without selecting input type=check box
, the NOTICE will appear so please tell me how to avoid it? I ask it because when I do with input type=text
, the NOTICE doesn't appear.
<?php
if(isset($_POST['submit'])) {
echo $_POST['check'];
}
?>
<form action="" method="post">
<input type="check box" name="check" value="1">
<input type="submit" name="submit">
</form>
empty() checks variable is set or not and also it has any value both...
<?php
if(!empty($_POST['submit'])) {
echo $checkbox_value = !empty($_POST['check'])?$_POST['check']:'--';
}
?>