If anybody can help I would very very appreciate this!
The problem is that I?m trying to build a survey! In admin screen there is
choice of questions to create (check box, radio, combo and comments)
Once admin creates questions with particular radio buttons set, then he can
add answers with radio buttons next to it.
Then it adds all that to database.
For users to see this survey with multiple questions and answers I have
created form in which all this is visible. For radio buttons to appear I need
to loop through the query which selects all created questions and answers.
However, for radio buttons to appear as grouped I use name = #questionID# from
query ? so that radio buttons will be grouped for each question.
My problem is since it is like:
<CFLOOP query="radioCheckView">
<INPUT type="Checkbox" name="selCheck"
value="<CFOUTPUT>#checkBoxQuest#</CFOUTPUT>">
<CFOUTPUT>#checkBoxQuest#</CFOUTPUT><br>
</CFLOOP>
Once user submits the form, all answers should be inserted into database.
How then this radio button can be identified when you submit?
<CFIF isDefined("Form.Submit")>
<CFOUTPUT query="ViewQuests">
<CFQUERY name="UserInsert" datasource="surveyDB">
INSERT INTO answers
(questID, comments, radio)
VALUES
(
#questID#,
'#form.comment#',
'#form.??????????? #' ? ?Don?t know what should I write here?
)
</CFQUERY>
</CFIF>
Please guys if you know how to solve this problem ? help me!
THANK YOU VERY VERY MUCH IN ADVANCE!
V.K.R - 24 Mar 2008 06:03 GMT
Hi
You have to give one more checking in side the cfloop before trying to insert
For eg: <cfif isDefined(Form.questionID)> and before closing the loop you have
to close the condition </cfif>
This will only insert the selected data that you have selected (radio button)
in the form.
I think this will fix your issue.
BKBK - 24 Mar 2008 10:23 GMT
Here is an example that answers your question. Remarks:
1) There is, as usual, just [i]one name[/i] for the radio fields. It is
assigned dynamically as #questionid#.
2) The radio fields have different values, also assigned dynamically by means
of the array radioquest.
3) When the form is submitted the dynamic value #questionid# will not exist on
the action page. One solution is to store it in a hidden field.
<cfif isdefined("form.sbmt")>
<!--- answer to your question: name of radio field is stored in hidden field
qid --->
selected value of radio field: <cfoutput>#form[form.qid]#</cfoutput>
<cfabort>
</cfif>
<cfset n=1>
<cfset questionid="z1x2c3">
<cfset radioquest = arraynew(1)>
<cfoutput>
<form action="#cgi.script_name#" method="post">
<cfloop from="1" to="5" index="i">
<cfset radioquest[n]="myradio"&i&"quest">
<input type="radio" name="#questionid#"
value="#radioquest[n]#">#radioquest[n]#<br>
</cfloop>
<input type="hidden" name="qid" value="#questionid#">
<input type="submit" name="sbmt" value="log in">
</form>
</cfoutput>
ajithmanmu - 28 Mar 2008 11:36 GMT
Hi,
the radio buttons,checkboxes,Multi select dropdown etc will only be defined if
they are selected in the form. So while using these u have to check whether
they are defined or not, then u have to do the DB operations.