Skip to main content
Participant
February 27, 2008
Question

cfinput type="checkbox" default value not posting

  • February 27, 2008
  • 3 replies
  • 611 views
Hello,

Any help I can get with this issue would be appreciated, as I am new to ColdFusion and have been banging my head against the wall with this for hours.

Here is the code for my form page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<cfparam name="form.cd" default="1">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<cfform method="post" action="test2.cfm">
<cfinput type="checkbox" name="form.cd" value="2">Test my checkbox
<input type="submit" name="Submit" value="Submit" />
</cfform>
<cfoutput>#form.cd#</cfoutput>
</body>
</html>

And here is the code for my action page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<cfif isdefined("form.cd")>yes</cfif>

</body>
</html>

In this configuration, whether the box is checked or not, my response page does not display anything.

I have also tried a variety of other solutions on the action page such as:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<cfparam name="form.cd" default="1">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<cfoutput>#form.cd#</cfoutput>

</body>
</html>

In this scenario, my page always displays the default value of 1.

I have also tried the previous scenario without the cfparam tag in the action page, since I set the default value of the form.cd tag in the form page. In that scenario, when the box is check, I get the result of 2 on the action page. If the box is not checked, I get the Element CD is undefined in FORM.

I know that an unchecked box does not get passed to the action page, but I thought that setting the default value would mean that the default value gets passed. Additionally, when I set the default value on the action page, I thought that the default value would only be assigned if the variable didn't already have a value, and I know that the checked box value of 2 is getting assigned, because it comes through when the box is checked and there is no cfparam tag on the action page.

Please, please, please help me understand this!!!

Many thanks!
    This topic has been closed for replies.

    3 replies

    bwccoderAuthor
    Participant
    February 27, 2008
    Thanks, cfsearching! I'll be sure to use that next time!
    bwccoderAuthor
    Participant
    February 27, 2008
    Thank you so so so much! It works now :-)
    Inspiring
    February 27, 2008
    bwccoder,

    You are correct in your thinking about how cfparam works. As you discovered the only problem was the form field name. In case you are curious, the problem was that this code

    <cfinput type="checkbox" name="form.cd" value="2">Test my checkbox

    Created a form field named "form.cd", not just "cd". In other words: form.form.cd
    For future reference, cfdump is a great tool for investigating problems like this. Since FORM is a structure, you can view all of the submitted form fields using:

    <cfdump var="#FORM#">

    It works for the URL scope as well.

    <cfdump var="#URL#">
    Inspiring
    February 27, 2008
    No need for the form.cd as name, just need cd

    This:

    <cfinput type="checkbox" name="form.cd" value="2">

    Should be this:

    <cfinput type="checkbox" name="cd" value="2">

    --
    Ken Ford
    Adobe Community Expert - Dreamweaver
    Fordwebs, LLC
    http://www.fordwebs.com


    "bwccoder" <webforumsuser@macromedia.com> wrote in message
    news:fq4k99$o4e$1@forums.macromedia.com...
    > Hello,
    >
    > Any help I can get with this issue would be appreciated, as I am new to
    > ColdFusion and have been banging my head against the wall with this for
    > hours.
    >
    > Here is the code for my form page:
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <cfparam name="form.cd" default="1">
    > <html xmlns=" http://www.w3.org/1999/xhtml">
    > <head>
    > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    > <title>Untitled Document</title>
    > </head>
    >
    > <body>
    > <cfform method="post" action="test2.cfm">
    > <cfinput type="checkbox" name="form.cd" value="2">Test my checkbox
    > <input type="submit" name="Submit" value="Submit" />
    > </cfform>
    > <cfoutput>#form.cd#</cfoutput>
    > </body>
    > </html>
    >
    > And here is the code for my action page:
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns=" http://www.w3.org/1999/xhtml">
    > <head>
    > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    > <title>Untitled Document</title>
    > </head>
    >
    > <body>
    >
    > <cfif isdefined("form.cd")>yes</cfif>
    >
    > </body>
    > </html>
    >
    > In this configuration, whether the box is checked or not, my response page
    > does not display anything.
    >
    > I have also tried a variety of other solutions on the action page such as:
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <cfparam name="form.cd" default="1">
    > <html xmlns=" http://www.w3.org/1999/xhtml">
    > <head>
    > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    > <title>Untitled Document</title>
    > </head>
    >
    > <body>
    >
    > <cfoutput>#form.cd#</cfoutput>
    >
    > </body>
    > </html>
    >
    > In this scenario, my page always displays the default value of 1.
    >
    > I have also tried the previous scenario without the cfparam tag in the
    > action
    > page, since I set the default value of the form.cd tag in the form page.
    > In
    > that scenario, when the box is check, I get the result of 2 on the action
    > page.
    > If the box is not checked, I get the Element CD is undefined in FORM.
    >
    > I know that an unchecked box does not get passed to the action page, but I
    > thought that setting the default value would mean that the default value
    > gets
    > passed. Additionally, when I set the default value on the action page, I
    > thought that the default value would only be assigned if the variable
    > didn't
    > already have a value, and I know that the checked box value of 2 is
    > getting
    > assigned, because it comes through when the box is checked and there is no
    > cfparam tag on the action page.
    >
    > Please, please, please help me understand this!!!
    >
    > Many thanks!
    >