WORKING WITH SINGLE VALUE CHECK BOXES IN FORMS - Dec 23rd, 2015


Here's how to add a checkbox (called non_member) to a form and have it populate a single value check box field in your
multi record editor

(Of course, you'll need to have a single value check box field called non_member in your multi record editor)

Check boxes are handled a bit differently from text field, so here's the code you'd need.

First create a variable (makes it easier to keep track of your code)




$non_memberCheckBox = intval(@$_REQUEST['non_member']);



Then, in your INSERT INTO or UPDATE mysql_query:



non_member = '".intval( $non_memberCheckBox )."',


Then in your form you would add:


<label for='non_member><span class="your_class">Non-Member:</span>&nbsp; </label>
<input type = "checkbox" id="non_member" name="non_member" value = "1" <?php checkedIf(1,
@
$_REQUEST['non_member']);?> />


So that if the box is checked your non_member field will be populated with a value of "1" If not it will be populated
with "0"



Another iteration of this is when $colsToValues is used (like in the profile update and user signup form)

When a browser submits a form if a checkbox is not ticked it doesn't send a value at all as opposed to sending an empty
or negative value.

To get around this issue, in the $colsToValues array, insert:


$colsToValues['non_member'] = (@$_REQUEST['non_member'])? '1' : '0' ;


Which sends a '0' when the box is unchecked.

In your form, your input field would look the same as above:


<input type = "checkbox" id="non_member" name="non_member" value = "1" <?php checkedIf(1, @$_REQUEST['non_member']);?>


WORKING WITH MULTI VALUE CHECK BOXES IN FORMS




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service