Problems with Checkboxes in Membership Edit Profile Form

8 posts by 4 authors in: Forums > CMS Builder
Last Post: April 1, 2015   (RSS)

Hi guys,

I am up against a wall... I'm trying to add a field called show_contact that when clicked on an edit account page will change the values of show_contact.

Here is my code for form input field

<input type="checkbox" name="show_contact" value="<?php echo htmlencode(@$_REQUEST['show_contact']); ?>"/>

I also added the field in the _post call

$colsToValues['show_contact']         = $_REQUEST['show_contact'];

When I check the box and save nothing happens on the backside and i get the following error.

MySQL Error: Incorrect integer value: '' for column 'show_contact' at row 1

Please help me! Thanks so much!

CR

By Mikey - March 19, 2015

Hey Matrix,

I think what you're missing is a method to determine the value of the field as checked or (1 for true). Below is a snippet of code I used on a form similar to what you're trying to achieve. I also changed the code to match yours.

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

If the above doesn't work, then try this line of code instead. The only difference is "1" is set to "Yes", which I bolded in both lines of code.

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

And the other portion - which you already have.

$colsToValues['show_contact']      = @$_REQUEST['show_contact'];

Hope this helps - Zicky

Thanks got this to work! Now I am having conflicts with twitter-bootstrap with the way they handle checkboxes....

http://getbootstrap.com/css/#forms

Instead of just a checked status they rewrite the html to having a span around the input.

Checked looks like this

<span class="checked">

<input checkbox>

</span>

Unchecked is the same without the span. I am also having trouble passing the values from the checkbox with the way bootstrap handles checkboxes. Anyone had to work around this before?

By Damon - March 20, 2015

I checked out the Bootstrap link, checked the checkbox and viewed the page source to see this:

<div class="checkbox">
  <label>
    <input type="checkbox"> Check me out
  </label>
</div>

What version of Bootstrap are you using?

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Damon - March 20, 2015

I checked out the Bootstrap link, checked the checkbox and viewed the page source to see this:

<div class="checkbox">
  <label>
    <input type="checkbox"> Check me out
  </label>
</div>

What version of Bootstrap are you using?

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

im using bootstrap 3.

By gregThomas - April 1, 2015

Hi,

I often use bootstrap in my projects, and have found that you can use the standard checked="checked" attribute in checkbox tags to load the checkbox as checked. Here is an example from a recent project:

                <div class="checkbox">
                  <label>
                    <input type="hidden" name="covered_by_insurance" value="0" />
                    <input name="covered_by_insurance" value="1" <?php checkedIf(@$_REQUEST['covered_by_insurance'], '1'); ?> type="checkbox"> Is this item covered by insurance? (Should it be included in insurance calculations)?
                  </label>
                </div>

The checkedIf function is built into CMS builder, and will echo checked="checked" if the two variables passed into it are the same.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com