CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Insert multiple checkbox values into a single database field

Print topic Send  topic

Author Message
codewarrior

Posts: 1
Posted: 05/22/2008, 2:14 PM

User can select multiple check boxes, can also select other check box , when other check box is selected , the text field is enabled and user can also add an entry into the text field.
How can I take multiple values to a single field in the database. Here is the code for the check boxes from the first form.

<b>Select one or more sub category:</b><br>
<INPUT TYPE='CHECKBOX' NAME=\"SUB_CATEGORY[]\" VALUE=\"one\"><b>One</b><br>
<INPUT TYPE='CHECKBOX' NAME=\"SUB_CATEGORY[]\" VALUE=\"two\"><b>Two</b><br>
<INPUT TYPE='CHECKBOX' NAME=\"SUB_CATEGORY[]\" VALUE=\"three\"><b>Three</b><br>
<INPUT TYPE='CHECKBOX' NAME=\"SUB_CATEGORY[]\" VALUE=\"Four\"><b>Four</b><br>
<INPUT TYPE='CHECKBOX' NAME=\"SUB_CATEGORY[]\" VALUE=\"other_2a\"onclick=\"this.form.OTHER_2B.disabled= !this.checked;\"><b>Other</b><br>
<table>
<tr><td><b>if other selected:</b></td><td><input TYPE=\"text\" NAME=\"OTHER_2B\" SIZE=\"10\" MAXLENGTH=\"10\" disabled='disabled'></td></tr>
</table>

View profile  Send private message
wkempees


Posts: 1679
Posted: 05/22/2008, 5:02 PM

CCS standard passes only first array value, you need to check rest yourself.
Assuming your multi checkbox is SUB_CATEGORY and your targetfield in the database is a_multi_response this snippet concatenates the returned values separated by comma's


$s_list = CCGetParam("SUB_CATEGORY", "");
if (count($s_list) > 0 AND is_array($s_list)) {
foreach ($s_list as $key => $value) {
if ($Component->a_multi_response->GetValue() != "")
$Component->a_multi_response->SetValue($Component->a_multi_response->GetValue() . ",");
$Component->a_multi_response->SetValue( $Component->a_multi_response->GetValue() . $value);
} // end for each
} // end if

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
jjrjr1


Posts: 942
Posted: 05/23/2008, 4:58 PM

Hi

This method works great and will do what you want for the database field.

Let me know if you want the checkboxes to be all checked correctly what you read that data field back and display the form.

It is really convoluted but can be done.


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.