Ask a Question related to Macromedia ColdFusion, Design and Development.
-
bill_doe #1
Hopefully simple syntax issue with forms
First let me say that I am relatively new to ColdFusion. Hopefully you gurus
out there will be able to steer me int he right direction.
I have a form that has radio buttons listed for a number of questions. Each
set of radio buttons is named on the form based on a question id (i.e.,
<cfinput type="radio" name="questionid#SurveyQuestions.QuestionID#" value="a
value">). When I go to the form handler and try to set a variable equal to
that value, I'm having a problem. I am also sending a list of the question ids
as a hidden field to the form handler.
On the form handler, I thought I could just do something like:
<cfloop index="FormQuestionID" list="#Form.QuestionIDs#">
<cfset Responses = Responses & ", " & #FormQuestionID#>
</cfloop>
The #FormQuestionID# comes across okay when I just cfoutput it (i.e.,
"Form.questionid5", but when I use it here it's giving me the a list of values
like "Form.questionid5, Form.questionid15, Form.questionid16,
Form.questionid17" for Reponses. So it's giving me the string value of
"Form.questionid5" instead of the form value of questionid5, which should be a
numeric value.
Any ideas how I could fix this or code this better?
Thanks!
Bill
bill_doe Guest
-
SQL syntax issue
Hi all, I'm using CFMX (v6), by the way. I'm try to cobble together a search page that will take the information input on a form and search... -
Simple syntax question
Hi I don't remember how to get the diplayed result broken in multiple lines. The command: mysql> SHOW INDEX FROM recentchanges; gives one... -
dummy here needs simple MySQL syntax help
Need to retrieve a specific row from table but only have the record number ( from a previous queryname.currentrow) passed as a form var to reference... -
simple syntax issue?
Hi, I just want a function to return true, but after a LoadVars.onLoad event. Am I right in assuuming that the return in the onLoad = function... -
Simple PHP Headers Syntax Question
What is the correct syntax to add a variable to a query string using the GET method of a form? I am trying to pass a dynamic variable ('$username').... -
dempster #2
Re: Hopefully simple syntax issue with forms
Form fields are passed to ColdFusion as a structure. If you know the name of
the field, you can refer to it in dot notation in a format such as:
Form.questionID25
The other way to refer to it is in associate array syntax: Form["questionID25"]
This syntax is also useful in a case such as yours, where the field name is a
variable. Try something like this:
<cfloop index="FormQuestionID" list="#Form.QuestionIDs#">
<cfset Responses = Responses & ", " & Form["#FormQuestionID#"]>
</cfloop>
-Paul
dempster Guest
-
bill_doe #3
Re: Hopefully simple syntax issue with forms
Thanks Paul. I tried it, but now I'm getting the error below. FYI,
"questionid5" is the first value in the #Form.QuestionIDs# list.
Thanks!
Bill
"Element questionid5 is undefined in a Java object of type class
coldfusion.filter.FormScope referenced as
The error occurred in
C:\Inetpub\wwwroot\Win2K_Desktop\Survey\survey_tha nks.cfm: line 35
33 : <cfset Responses = "">
34 : <cfloop index="FormQuestionID" list="#Form.QuestionIDs#">
35 : <cfset Responses = Responses & ", " & Form["#FormQuestionID#"]>
36 : </cfloop>
37 : <cfoutput>#Responses#</cfoutput><p>"
bill_doe Guest
-
mxstu #4
Re: Hopefully simple syntax issue with forms
If the form element numbers are consecutive (ie. with no gaps), you could just
store the total number of questions in your hidden form field, and on the
action page, loop from 1 to the #form.totalNumberOfQuestions# and retrieve the
answer for each question. Note: Since, you're using radio buttons, you may
need to use CFPARAM to ensure the form fields exist on the action page.
<!--- example: if you had 15 questions --->
<cfset form.totalNumberOfQuestions = "15">
<cfset Responses = "">
<cfloop from="1" to="#form.totalNumberOfQuestions#" index="counter">
<cfset Responses = ListAppend(Responses, Form["question"& counter])>
</cfloop>
<cfoutput>
#Responses#
</cfoutput>
mxstu Guest
-
dempster #5
Re: Hopefully simple syntax issue with forms
Are you sure that that the form field questionid5 is being sent?
You may need to check that a particular form field was submitted. Text fields
are always submitted even if they are blank, but radio buttons and checkboxes
would not be submitted if a selection was not made. In those cases, you'd have
to check that a field exists first. In dot notation you could use
IsDefined("Form.questionid5"). Checking as a structure, you'd use
StructKeyExists(structure, key) to see if it is defined.
-Paul
dempster Guest
-
bill_doe #6
Re: Hopefully simple syntax issue with forms
Yeah, that was the first thing I checked. I just did a <cfoutput>#Form.response5#</cfoutput> and the value is definitely there.
bill_doe Guest
-
mxstu #7
Re: Hopefully simple syntax issue with forms
If the field is named "response5" then shouldn't the list of form field names be "response5,etc..." and not "questionid5, etc"...?
mxstu Guest
-
bill_doe #8
Re: Hopefully simple syntax issue with forms
Hey mxstu, I tried this code, but it looks like it's putting a space between
"question" and the value of counter.
"Element question 5 is undefined in a Java object of type class
coldfusion.filter.FormScope referenced as
The error occurred in
C:\Inetpub\wwwroot\Win2K_Desktop\Survey\survey_tha nks.cfm: line 91
89 : <cfset Responses = "">
90 : <cfloop list="#Form.QuestionIDs#" index="counter">
91 : <cfset Responses = ListAppend(Responses, Form["question" & counter])>
92 : </cfloop>
93 : "
bill_doe Guest
-
bill_doe #9
Re: Hopefully simple syntax issue with forms
Sorry, I mistyped. I corrected in almost right away, but you must have seen my mistake before I corrected it!
bill_doe Guest
-
mxstu #10
Re: Hopefully simple syntax issue with forms
Two things, I realized your form fields have "ID" in the name, so you need to
change this statement
<cfset Responses = ListAppend(Responses, Form["question"& counter])>
to
<cfset Responses = ListAppend(Responses, Form["questionID"& counter])>
Hey mxstu, I tried this code, but it looks like it's putting a space between
"question" and the value of counter.
No, this syntax should not add a space. If the value of counter is 5, then
the output would be question5 (no space)
mxstu Guest
-
mxstu #11
Re: Hopefully simple syntax issue with forms
Oh, I see that you're using different code than what I posted in my example.
If the there is a space in the output question 5 then your list must contains spaces.
mxstu Guest
-
bill_doe #12
Re: Hopefully simple syntax issue with forms
Roger that. Got it working. Thank you guys so very much for your help!
bill_doe Guest



Reply With Quote

