Membership plugin - Echo current value of checkbox

Re: [gkornbluth] Membership plugin - Echo current value of checkbox

By Jason - October 18, 2010

Hi Jerry,

A checkbox in CMS Builder can only store a value of either 1 or 0. However, in your form you're using 2 check boxes. The problem with this is that there is nothing to prevent a user from checking both.

What you need to do is to display your form element as either selected or unselected based on the value currrently stored in the database. There are two solutions that you could use.

1) You can use a single check box to allow them to decide if they want to share their email address or not. If they had previously checked yes, the box on the form will be checked, otherwise, it will be blank:

<tr>
<td class="body-text-bold-9" valign="top">Share my e-mail address with other Art organizations:</td>
<td class="body-text-9" valign="top"><input type="checkbox" name="share" value="1" <?php if(@$_REQUEST['share']){echo "checked='checked'";}?> /> </td>
</tr>


2) The other option would be to use radio buttons for yes and no. This way they can only select 1:
<tr>
<td class="body-text-bold-9" valign="top">Can we share your e-mail address with other Art organizations</td>
<td class="body-text-9" valign="top"><input type="radio" name="share" value="1" <?php if(@$_REQUEST['share']){echo "checked='checked'";}?> /> Yes please<br />
<input type="radio" name="share" value="0" <?php if(!@$_REQUEST['share']){echo "checked='checked'";}?>> No Thanks<br /></td>
</tr>


The second solution is probably closer to what you are currently trying.

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/

Re: [Jason] Membership plugin - Echo current value of checkbox

Thanks Jason.

Appreciate the help!

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php