close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Combine checkbox fields into a checkbox group

Thread began 11/02/2012 6:10 am by info4753 | Last modified 11/12/2012 10:36 am by Jason Byrnes | 1488 views | 13 replies |

info4753

Combine checkbox fields into a checkbox group

I have multiple database fields shown as checkboxes in a form. I'd like to collect them into a checkbox group in order to validate that at least one of them is being seleced.

I can't find a way to accomplish this. I tried to define the checkbox fields as checkbox group but this comes out as multiple checkbox groups instead of one group with multiple checkboxes...

Thanks for any help.

Sign in to reply to this post

Jason ByrnesWebAssist

a checkbox group is a collection of checkboxes, all with the same name. For a checkbox group to work correctly, the name needs to end with []. for example:

<label>
<input type="checkbox" name="checkGroupA[]" value="1" id="checkGroupA_0" />
One</label>
<br />
<label>
<input type="checkbox" name="checkGroupA[]" value="2" id="checkGroupA_1" />
Two</label>
<br />
<label>
<input type="checkbox" name="checkGroupA[]" value="3" id="checkGroupA_2" />
Three</label>
Sign in to reply to this post

info4753

Thx. But why is there a checkboxgroup configuration in DataAssist Pages when it can't be used to enter data into the database? Or do I miss here something? That's confusing.

I try to build the basic form with DataAssist, the CheckboxGroup with Fombuilder and try to finish a running form buy moving the FB code to the DA Form. But Validation is not working correctly so far ...

Sign in to reply to this post

info4753

Is a checkbox group the right way to go for this problem at all?

Sign in to reply to this post

Jason ByrnesWebAssist

  Thx. But why is there a checkboxgroup configuration in DataAssist Pages when it can't be used to enter data into the database? Or do I miss here something? That's confusing.  




Well, a checkbox group can be used to enter data to the database. A checkbox group is basically the same idea as a multiple select list. It allows the user to choose multiple options and store the values into a column of your database table

  Is a checkbox group the right way to go for this problem at all?  

i don't know. What exactly is it you are trying to accomplish?

Sign in to reply to this post

info4753

I've got 5 database fields (tinyint). In the users form there will be 5 checkboxes for these database fields. What I try to accomplish is a validation on these 5 checkboxes that at least one of them has to be selected by the user.

Sign in to reply to this post

Jason ByrnesWebAssist

This would require custom code to accomplish.

you could validate the checkboxes using the following code:

php:
<?php

if($_SERVER['REQUEST_METHOD'] == "POST") {
if((!isset(
$_POST['field1']) || $_POST['field1'] == "") && (!isset($_POST['field2']) || $_POST['field2'] == "") && (!isset($_POST['field3']) || $_POST['field3'] == "") && (!isset($_POST['field4']) || $_POST['field4'] == "") && (!isset($_POST['field5']) || $_POST['field5'] == "")) {
        @
session_start();
        
$_SESSION['failed'] = "true";
        
header("Location: "$_SERVER['PHP_SELF']);
        exit;
    }
}
?>




this assumes the checkboxes are named "field1", "field2", "field3", "field4", and "field5"


then use this code to show an error message;

php:
<?php @session_start(); if(isset($_SESSION['failed']) && $_SESSION['failed'] == "true") { ?>At least one box must be checked<?php unset($_SESSION['failed']); } ?>
Sign in to reply to this post

info4753

Thx Jason I'll try this out

Sign in to reply to this post

info4753

The code works but all the other data entered (into the other fields) by the customer will be lost.

How can I keep the field data alive and/or how can I validate the checkboxes before the form is been submitted?

Thanks for any help.

Sign in to reply to this post

Jason ByrnesWebAssist

are you using server validations to validate other fields on the fields on the form?

or are the checkboxes the only fields you want to validate?

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...