Question
cfinput type="checkbox" default value not posting
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!
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!