lrintoul Posted July 15, 2010 Share Posted July 15, 2010 I'm working on an online application form with a few checkboxes. They are yes or no answers. The form information is sent via email to the company for review. This is part of the code from the form: Hours of Experience: <input name="hours" id="hours" class="info" type="text" size="15" value="<?php echo (isset ($_POST['hours'])? $_POST['hours'] : "");?>"/> Do you have a current Driver's License? Yes <input name="license_yes" id="license_yes" type="checkbox" size="10" value="<?php echo (isset ($_POST['license_yes'])? $_POST['license_yes'] :"");?>"/> No <input name="license_no" id="license_no" type="checkbox" size="10" value="<?php echo (isset ($_POST['license_no'])? $_POST['license_no'] : "");?>""/></td> This is code to be posted in the form email. I can get the general text info to post but I don't know how to post the checkbox answers. Hours of Experience: '.$_POST["hours"].' I'd really appreciate some help. Thanks. Link to comment https://forums.phpfreaks.com/topic/207868-php-posting-checkbox-yesno-to-form/ Share on other sites More sharing options...
radar Posted July 15, 2010 Share Posted July 15, 2010 I would actually make those check boxes, radio buttons and name them the same thing -- this way only one of them can be selected at a time and you only have to look at one post variable instead of a yes and no variable. then you would access it just like everything else via $_POST Link to comment https://forums.phpfreaks.com/topic/207868-php-posting-checkbox-yesno-to-form/#findComment-1086661 Share on other sites More sharing options...
gwolgamott Posted July 15, 2010 Share Posted July 15, 2010 They are only sent to the post if they are checked for checked boxes. Thus do a simple isset() check... if not set then it was not sent and thus not checked. if(isset($_POST['license_yes'])){ //It's checked do something with it. } if(isset($_POST['license_no'])){ //It's checked do something with it. } But of course I agree with radar if this a yes / no question then it needs to be radio buttons so they can't both be checked. Link to comment https://forums.phpfreaks.com/topic/207868-php-posting-checkbox-yesno-to-form/#findComment-1086666 Share on other sites More sharing options...
lrintoul Posted July 16, 2010 Author Share Posted July 16, 2010 Excellent - thanks for the help! Link to comment https://forums.phpfreaks.com/topic/207868-php-posting-checkbox-yesno-to-form/#findComment-1086868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.