Ask a Question related to Coldfusion Database Access, Design and Development.
-
MajikMerlin #1
Dynamic <INPUT name=" "> attributes
Hello everyone.
I seem to be in a rut on a local intranet web application im working on. I am
developing a questionaire for a portion of the intranet site that deals with
surveys. The trouble I am running into is when it comes to update the database
I want to insert the submitted data into. Before I continue I try to explain
how this form and submission process works.
I have table in MSSQL that contains a list of questions each with a unique ID
(questionID) and another table that contains the answers. So right now, I have
two tables, one for the answers (tblAnswers) and one that contains the
questions (tblQuestions). Each table has a "questionID" field, one Primary Key
field (in tblQuestions) and one Foreign Key field (in tblAnswers).
The database tables works just fine so I am pretty confident of the
architecture of the two tables.
Here is my problem:
I am assiging the <FORM> attribute, "name=", a dynamic name. The dynamic name
is the questionID from tblQuestions. So this looks something like this:
<CFQUERY name="RetrieveQuestions" datasource="#application.ds#">
select * from tblQuestions
</cfquery>
<CFFORM name="myQuestions" action="myQuestions_insert.cfm>
<tr>
<cfoutput query
<td>#questionBody#<td>
<td><INPUT NAME=#questionID# type="text">
</CFFORM>
So this forms works just fine, it retrieves the correct questions and displays
them and submits correctly. Now the major hiccup occurs. When it reaches the
action-form "myQuestions_insert.cfm" i am having trouble retrieving the
dynamically created FORM.<name> data (i.e. the answer to the question).
So, in other words, if the questionID is '256' , a form element with the
name '256' would be created. So to retrieve this I would insert the following
CFML.
<cfoutput> #FORM.256# <cfoutput>
It works fine if i hard code the value of the question, the thing is i have
hundreds of questions in the table and what I am trying to do is retrieve is
the <name> portion of #FORM.<name>#. the closest i got to resolving this
issue is that i created a <cfset> variable and tried to store the data in that.
Here's the code:
<cfset answer = 'FORM.#quesionID#'>
Unfortunately CF treats this as a string and thats is just fine, but if i
include the variable in the my query to input the data, it inputs the created
string into the table. So i would have an answer as "FORM.256" and not what
#FORM.256# is. I would like to retrieve what #FORM.256# contains and then post
the answer into the database table (tblAnswers).
Does anyone have any idea on how to correctly implement this? i have been
stuck on this for 2 days now and I dont think it should be this difficult to do
something that seams simple.
Thanks in advance and i'm looking forward to any ideas or solutions.:confused;
MajikMerlin Guest
-
Setting "URL Behaviour" to "Dynamic" has no effect
Greetings When I set the "URL Behaviour" of a web reference an entry is created in the "Web.config", but the value in the "Web Reference URL"... -
could not read block 84253 of relation "tablename": Input/outputerror
Hi: No way to access "tablename". Can I do something to recover? Is this a hardware error? PostgreSQL 7.4.5 on i686-pc-linux-gnu, compiled by... -
Problem with fopen("php://input", "r")
Hello there, I am having problem opening the in-built php stream php://input According to the manual this has been integrated into php since... -
custom checkboxlist, attributes.add("Value",1) does not work
Hello. I'm trying to create a custom checkboxlist, that uses a datarow as input to populate them. This works just fine, except that I can't seem... -
"buddy api" folder attributes
Hi there, Is it possible to set the attribute of a folder to hidden using Buddy api? The help mentions that you can set the attribute of a file to... -
mxstu #2
Re: Dynamic <INPUT name=" "> attributes
<!----- FORM PAGE ----->
<form action="yourActionPage.cfm" method="post">
<table border="1">
<tr>
<td><b>Row</b></td>
<td><b>Quest. ID</b></td>
<td><b>Answer</b></td>
</tr>
<cfoutput query="RetrieveQuestions">
<tr>
<td>#CurrentRow#</td>
<td>#questionID#</td>
<td><input type="text" name="answer#CurrentRow#">
<input type="hidden" name="questionID#CurrentRow#" value="#questionID#">
</td>
</tr>
</cfoutput>
</table>
<cfoutput>
<input type="hidden" name="numberOfQuestions"
value="#RetrieveQuestions.recordCount#">
</cfoutput>
<input type="submit">
</form>
<!-------- ACTION PAGE --------->
<cfloop from="1" to="#form.numberOfQuestions#" index="row">
<!--- copy values into local variables --->
<cfset currentQuestionID = form["questionID"& row]>
<cfset currentAnswer = form["answer"& row]>
<!--- replace this debug output with your insert query --->
<cfoutput>
Row [#row#]: QuestionID = #currentQuestionID#<br>
Row [#row#]: Answer = #currentAnswer#<br><br>
</cfoutput>
</cfloop>
mxstu Guest
-
MajikMerlin #3
Re: Dynamic <INPUT name=" "> attributes
Awesome!
Thanks mxstu, this is just the technique I needed.
MajikMerlin Guest



Reply With Quote

