Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
June Macleod #1
problem saving form results to a database table
Coldfusion MX
MSDE 2000
I have a form on a page which users either fill in text or check radio
buttons. The form has the following properties:
<FORM action="sampleUpdate.cfm" METHOD="post" enctype="multipart/form-data"
NAME="MainForm" >
The sampleUpdate.cfm form writes the values in the form back to the SQL
table:
<cfquery datasource="SurveySQL">
INSERT INTO dbo.Results(dbo.Results.RID,
dbo.Results.QID,dbo.Results.ResponderName,dbo.Resu lts.Company,dbo.Results.[P
osition],dbo.Results.Email,dbo.Results.Q1,dbo.Results.Q2,d bo.Results.Q3,dbo.
Results.Q4,dbo.Results.Q5,dbo.Results.Q6,dbo.Resul ts.Q7,dbo.Results.Q8,
dbo.Results.Q9, dbo.Results.Q10, dbo.Results.Q11, dbo.Results.Q12,
dbo.Results.Q13 )
VALUES
('999','1','#form.wsb33#','#form.wsb34#','#form.ws b35#','#form.wsb36#','#for
m.wsb0#',
'#form.wsb1#','#form.wsb2#','#form.wsb3#','#form.w sb4#','#form.wsb5#','#form
..wsb6#','#form.wsb7#',
'#form.wsb8#','#form.wsb9#','#form.wsb10#','#form. wsb11#','#form.wsb12#')
</cfquery>
This all works fine and the Result table is updated provided that the user
has completed each item on the form.
If the user misses out a question such as No. 3 I get an 'Undefined wsb3'
error when trying to run the Insert query.
I want the user to have the flexability to miss out questions if they so
desire and wonder if there is a way to intercept the answer from the
#form.wsb3# variable and check if it is defined or null. I tried using
ISDEFINED() and IFNULL() within the query but to no avail.
Any help would be much appreciated.
Regards
June
June Macleod Guest
-
Display results from a database in a table side by side
While working on a page, I needed to display titles for certain series organized in a table. But I need these organized side by side. In other... -
Query results don't display properly in results table.IGNORE PREVIOUS
:disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in... -
Query results don't display properly in results table.
:disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in... -
Problem with accessing table in access database
i had a working site with iis5 winxp professional on a p4 machine. suddenly i am having problems with and the asp pages which have some updating... -
Saving serialized data to database problem
Hi! Anyone who knows about saving serialized data to database, coz I have a problem with that. If I just serialize my session data and then... -
johnab #2
Re: problem saving form results to a database table
if you're using checkboxes then they don't get passed across if they haven't
been checked.
Your best solution would be to use cfparam to param values to a default if
they haven't been selected, eg, FALSE, NO etc
<cfparam name="form.myformfield" default="False">
make sense?
johnab Guest
-
jdeline #3
Re: problem saving form results to a database table
Unchecked radio buttons will not pass the button's name to the action page,
thereby making it undefined. For each form variable, place a CFPARAM at the
top of the action page:
<CFPARAM NAME="wsb1" DEFAULT="">
This defines wsb1 as "" if it is not provided by the form page; if it is
present, it has the value entered on the form.
jdeline Guest
-
BKBK #4
Re: problem saving form results to a database table
1) The cfparam tags are to be placed just before the query.
2) As Johnab and Jdeline suggest, you have to do something to ensure that radio
and checkbox field-names will be submitted. For example, use the
checked-attribute.
<input type="Radio" name="wsb3" value="answer3a" checked>
<input type="Radio" name="wsb3" value="answer3b">
3) There is an alternative solution to your problem, which may be useful when
the
number of form fields is large. For example, it may save you form writing
many
cfparam tags for the same default value. If your form is
<FORM action="sampleUpdate.cfm" METHOD="post" enctype="multipart/form-data"
NAME="MainForm" >
wsb1 <input name="wsb1" type="Text" size="20" maxlength="20"><br>
wsb2: <input type="Radio" name="wsb2" value="answer_1" checked><br>
<input type="Radio" name="wsb2" value="answer_2"><br><br>
etc.
etc.
<input name="score" type="Submit" value="log in">
</form>
then you can do something like this on your action-page, sampleUpdate.cfm,
just before the query:
<cfif isdefined("Form.fieldNames")>
<cfloop list="#Form.fieldNames#" index="formfield">
<!--- Considering all fields except the submit-field, if field
value is empty, enter an "x". --->
<cfif NOT(formfield is "score")>
<cfset formfieldValue = Evaluate("form.#formfield#")>
<cfif Len(formfieldValue) EQ 0>
<cfset form[formfield] = "x">
</cfif>
</cfif>
</cfloop>
</cfif>
BKBK Guest
-
June Macleod #5
Re: problem saving form results to a database table
Thank you all for your responses.
I now understand what the problem is and was able to get it working.
Much appreciated!
June
"June Macleod" <junework@hotmail.com> wrote in message
news:dkfkdh$qh8$1@forums.macromedia.com...enctype="multipart/form-data"> Coldfusion MX
> MSDE 2000
>
> I have a form on a page which users either fill in text or check radio
> buttons. The form has the following properties:
>
> <FORM action="sampleUpdate.cfm" METHOD="post"dbo.Results.QID,dbo.Results.ResponderName,dbo.Resu lts.Company,dbo.Results.[P> NAME="MainForm" >
>
>
> The sampleUpdate.cfm form writes the values in the form back to the SQL
> table:
>
> <cfquery datasource="SurveySQL">
> INSERT INTO dbo.Results(dbo.Results.RID,
>osition],dbo.Results.Email,dbo.Results.Q1,dbo.Results.Q2,d bo.Results.Q3,dbo.>('999','1','#form.wsb33#','#form.wsb34#','#form.ws b35#','#form.wsb36#','#for> Results.Q4,dbo.Results.Q5,dbo.Results.Q6,dbo.Resul ts.Q7,dbo.Results.Q8,
> dbo.Results.Q9, dbo.Results.Q10, dbo.Results.Q11, dbo.Results.Q12,
> dbo.Results.Q13 )
> VALUES
>'#form.wsb1#','#form.wsb2#','#form.wsb3#','#form.w sb4#','#form.wsb5#','#form> m.wsb0#',
>> .wsb6#','#form.wsb7#',
> '#form.wsb8#','#form.wsb9#','#form.wsb10#','#form. wsb11#','#form.wsb12#')
> </cfquery>
>
> This all works fine and the Result table is updated provided that the user
> has completed each item on the form.
>
> If the user misses out a question such as No. 3 I get an 'Undefined wsb3'
> error when trying to run the Insert query.
>
> I want the user to have the flexability to miss out questions if they so
> desire and wonder if there is a way to intercept the answer from the
> #form.wsb3# variable and check if it is defined or null. I tried using
> ISDEFINED() and IFNULL() within the query but to no avail.
>
> Any help would be much appreciated.
>
> Regards
>
> June
>
>
>
>
June Macleod Guest



Reply With Quote

