Jump to content

php checkbox


dezkit

Recommended Posts

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

<?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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.