Using checkbox and radio buttons with addform.php

2 posts by 2 authors in: Forums > CMS Builder
Last Post: April 30, 2012   (RSS)

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:

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