Using checkbox and radio buttons with addform.php
2 posts by 2 authors in: Forums > CMS Builder
Last Post: April 30, 2012 (RSS)
By ScottL - April 28, 2012
How can I use a checkbox to get a returned value of Yes or No, or radio buttons in my forms with the addform.php?
<input type="checkbox" name="NAME" value="<?php echo htmlspecialchars(@$_REQUEST['NAME']); ?>" />
Thanks.
<input type="checkbox" name="NAME" value="<?php echo htmlspecialchars(@$_REQUEST['NAME']); ?>" />
Thanks.
Re: [ScottL] Using checkbox and radio buttons with addform.php
By Jason - April 30, 2012
Hi,
In CMS Builder checkboxes are stored as either 1 (true/checked) or 0 (false/unchecked). Another thing to keep in mind about check boxes in HTML is that if they are not checked, the form doesn't submit them to the server at all.
First, try setting up your check box like this:
Then, when processing the form, you can get the value of the checkbox like this:
If the check box was checked and submitted, this code will give you a value of 1. If the checkbox wasn't checked, you will get a value of 0. You can then use this variable in your INSERT statement.
Hope this helps
In CMS Builder checkboxes are stored as either 1 (true/checked) or 0 (false/unchecked). Another thing to keep in mind about check boxes in HTML is that if they are not checked, the form doesn't submit them to the server at all.
First, try setting up your check box like this:
<input type = "checkbox" name = "myCheckBox" value = "1" <?php checkedIf(1, @$_REQUEST['myCheckBox']);?> />
Then, when processing the form, you can get the value of the checkbox like this:
$myCheckBox = intval(@$_REQUEST['myCheckBox']);
If the check box was checked and submitted, this code will give you a value of 1. If the checkbox wasn't checked, you will get a value of 0. You can then use this variable in your INSERT statement.
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/