Reputation: 109
I am trying to study ColdFusion (just starting out) and got stuck while doing some testing.
Basically, I am trying to pass data from form.cfm to storage.cfm. However, the data does not seem to get passed/sent.
Here is form.cfm (please ignore the markup, this is only for testing and I am absolutely new to CF so you might see something awful :D)
<cfparam name="userId" default=0/>
<cfparam name="firstName" default=""/>
<cfparam name="lastName" default=""/>
<cfparam name="address" default=""/>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Learning CF</title>
<meta charset="UTF-8">
</head>
<body>
<h2>Persons Table - <cfif userId EQ 0>Add<cfelse>Edit</cfif></h2>
<form action="storage.cfm" method="POST">
<input type="hidden" name="userId" value="#userId#">
<cfdump var="#userId#"/>
<br/><br/>
<label>First Name:</label>
<input type="text" name="firstName" value="<cfoutput>#firstName#</cfoutput>"><br/><br/>
<label>Last Name:</label>
<input type="text" name="lastName" value="<cfoutput>#lastName#</cfoutput>"><br/><br/>
<label>Address:</label>
<input type="text" name="address" value="<cfoutput>#address#</cfoutput>"><br/><br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
the cfdump here tells me userId is 0. Here is storage.cfm
<cfparam name="form.userId" default=""/>
<cfdump var="#form.userId#"/>
When I hit submit, what shows up in storage.cfm is only
#userId#
Upvotes: 2
Views: 858
Reputation: 6236
You need to enclose the userid
between cfoutput
so that it can be evaluated. Or better just wrap the form inside cfoutput
.
<cfoutput>
<form action="storage.cfm" method="POST">
<input type="hidden" name="userId" value="#userId#">
<label>First Name:</label>
<input type="text" name="firstName" value="#firstName#">
<label>Last Name:</label>
<input type="text" name="lastName" value="#lastName#">
<label>Address:</label>
<input type="text" name="address" value="#address#">
<input type="submit" value="Submit">
</form>
</cfoutput>
Upvotes: 11