Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Coldfusion - form checkbox state and value

New Here ,
Apr 29, 2009 Apr 29, 2009

I have a web page that is showing 'Special Offers' that consist of id, title, intro, body_text and state, this information is retrieved from a mysql database.

The state indicates if the 'Special Offer' is active (the user can view it) or inactive (not visable to the user). When the state is inserted into the database active is '1' and inactive '0'.

QUESTION!

I'm trying to create an administration page so an administrator can change/update the state of the 'Special offer' by ticking or un-ticking the state checkbox. So far my update page shows the checkbox in the correct state but how do I send a new variable to the database when submitted if the checkbox is changed.

I'm not sure if that explains my problem clear enough, please email me if its not clear.

2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 29, 2009 Apr 29, 2009

I'm not exactly sure what you are asking, but let me take a guess:

If you are asking about how you handle updating your form's action page when you submit your form that contains your checkbox:

1) use <cfparam> on your action page to set a default value to your checkbox form variable

   e.g. <cfparam name="FORM.myCheckBoxField" default="0">

2) In your Update statement, use the value of yor check box field variable as the value you are setting your DB field to:

   e.g. UPDATE myTable

         SET title = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FORM.myTitleField#">,

         accessible = <cfqueryparam cfsqltype="CF_SQL_BIT" value="#FORM.myCheckBoxField#">

         WHERE myTableID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#Form.myRecordID#">

   or

        UPDATE myTable

         SET title = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FORM.myTitleField#">,

         <cfif FORM.myCheckBoxField eq 0>

               accessible = 0,

         <cfelse>

               accessible = 1,

         </cfif>

         WHERE myTableID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#Form.myRecordID#">

Hope that helps,

- Michael

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 29, 2009 Apr 29, 2009
LATEST

On your form page, put a hidden field, name=state, value=0 before your checkbox.

On your processing page, process listlast(form.state)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources