neeep Posted January 14, 2010 Share Posted January 14, 2010 If two inverted commas means nothing has been entered in a field, how would I say, a checkbox has not been ticked? $error = ' '; Link to comment https://forums.phpfreaks.com/topic/188457-checkbox-ticked-description/ Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 If a checkbox is NOT ticked it will NOT be posted with the form. so if (isset($_POST['checkbox'])) { echo 'It was ticked'; } else { echo 'It wasnt ticked'; } should give the desired result.. if you form method is post that is Link to comment https://forums.phpfreaks.com/topic/188457-checkbox-ticked-description/#findComment-994915 Share on other sites More sharing options...
neeep Posted January 14, 2010 Author Share Posted January 14, 2010 Thanks, That helped Now I need to say, "If one of these two checkboxes were not ticked, give this alert." The following code means "If forname or surname were not ticked, give this alert for each instance" $emailMessage .= "\nforename: " . $_POST['foreName']; $emailMessage .= "\nsurname: " . $_POST['surName']; $error = ''; if (!$surName) $error = $error."<b>Surname</b><br />"; if (!$foreName) $error = $error."<b>Forename</b><br />"; if ($error!="") echo "<span id='red'><font size='2'>Please fill out the following required fields:</font><br />$error</span>"; The following are my checkboxes $emailMessage .= "\n7day: " . (isset($_POST['7day'])); $emailMessage .= "\nexamonly: " . (isset($_POST['examonly'])); I need to make sure the user ticks at least one. If they tick none, I need an alert saying Please tick one of the boxes. Can you help me with this? Link to comment https://forums.phpfreaks.com/topic/188457-checkbox-ticked-description/#findComment-994932 Share on other sites More sharing options...
neeep Posted January 14, 2010 Author Share Posted January 14, 2010 sorry, forename and surname are input fields! They all work fine. Im just showing you how my file is set up. Link to comment https://forums.phpfreaks.com/topic/188457-checkbox-ticked-description/#findComment-994934 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 for your checkboxes you need something like this.. <?php if (!isset($_POST['7day']) || !isset($_POST['examonly'])) { // do your error stuff and tell them to choose one.. } else { // now you need to figure out which one they clicked.. if (isset($_POST['7day'])) { // 7 day was selected } else { //exam only was selected } } now this isnt a perfect example but you get the idea.. Link to comment https://forums.phpfreaks.com/topic/188457-checkbox-ticked-description/#findComment-994938 Share on other sites More sharing options...
neeep Posted January 14, 2010 Author Share Posted January 14, 2010 Hi, Thanks, the error stuff is working, but once I then click one of the boxes the error message remains and i dont move on.. if (!isset($_POST['7day']) || !isset($_POST['examonly'])) echo "<span id='red'><font size='2'>Pick a course:</font><br />$error</span>"; else { //SUBMIT & REDIRECT mail( "[email protected]", "Subject: $emailSubject", $emailMessage, "From: $Email" ); header("Location: thankyou.html"); } Can you tell why it's not moving on? It moves on to the email stage for the error messages which apply to one field not being filled in, so I know the submit and redirect is fine... Any ideas on the checkbox thing? Link to comment https://forums.phpfreaks.com/topic/188457-checkbox-ticked-description/#findComment-994965 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 My bad.. replace the || with && in the if statement... Link to comment https://forums.phpfreaks.com/topic/188457-checkbox-ticked-description/#findComment-994967 Share on other sites More sharing options...
neeep Posted January 14, 2010 Author Share Posted January 14, 2010 Perfect! thanks! This is my first time using php so sorry about the clulessness of syntax.. Link to comment https://forums.phpfreaks.com/topic/188457-checkbox-ticked-description/#findComment-994981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.