dezkit Posted May 5, 2008 Share Posted May 5, 2008 How do i do so that if a user checks a checkbox and submits the form, it says, "Checkbox has been selected." and if not selected, but submited, "Checkbox has not been selected." <?php if(isset($_POST['submit'])) { ????????????????????????????????????? } else { ?> <form action="<? $_SERVER['PHP_SELF']; ?>" method="post"> <input type="checkbox" name="checkbox"> <input type="submit" value="submit"> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/104254-php-checkbox/ Share on other sites More sharing options...
flyhoney Posted May 5, 2008 Share Posted May 5, 2008 <?php if(isset($_POST['submit'])) { if ($_POST['checkbox'] == 'SOMEVALUE') { // checkbox was checked } } else { ?> <form action="<? $_SERVER['PHP_SELF']; ?>" method="post"> <input type="checkbox" name="checkbox" value="SOMEVALUE"> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/104254-php-checkbox/#findComment-533720 Share on other sites More sharing options...
dezkit Posted May 5, 2008 Author Share Posted May 5, 2008 thanks for the code, but i want there to be a if and an else.. something like this <?php if(isset($_POST['submit'])) { if ($_POST['checkbox'] == 'SOMEVALUE') { echo "Checkbox was selected."; } else { echo "Checkbox was not selected."; } } else { ?> <form action="<? $_SERVER['PHP_SELF']; ?>" method="post"> <input type="checkbox" name="checkbox" value="SOMEVALUE"> <input type="submit" value="submit"> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/104254-php-checkbox/#findComment-533728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.