views:

48

answers:

2

The user will input their Id number then the accounts tied to this Id number will be presented(radio buttons) . They could have 1 or even 10 accounts returned(radio buttons). I need to have them update their account to a Y, N. The account Id is what makes up the radio groups. Now I need to know who to loop through these radio buttons to see what they selected.

<cfif isDefined('FORM.bnt2')>
    <cfloop index="i" list="#form.fieldnames#">
        <cfquery  name="accept" datasource="#request.dsn#">
            UPDATE opt SET 
            f14 = '#evaluate(i)#'
            WHERE f4 = '#FORM.id#'
        </cfquery>
    </cfloop>
</cfif>                                                              

<cfform  name="frm2" id="form2" method="post" action="">
    <cfinput type="radio" name="#f5#" value="y"> 
    <cfinput type="radio" name="#f5#" value="n">
    <cfinput type="hidden" name="id" value="#f4#" />
    <cfinput name="bnt2" type="image" class="btn" src="images/accept.gif" value="Submit"/>
+1  A: 

Don't use evaluate!

Do use cfqueryparam!

And fix those variables names, f5, btn2 etc are not good names.


Anyway, I'm not entirely certain what you're doing, but here's a code snippet for you:

<cfoutput>
<cfloop index="CurField" list="#Form.FieldNames#">
    <br/>#CurField#=#XmlFormat(Form[CurField])#
</cfloop>
</cfoutput>

That should give you what you need to make things work.

Note the XmlFormat is for display - generally not done in queries (storing data in the database), but instead when it is displayed to a browser. (Can also use HtmlEditFormat if you prefer.)

Peter Boughton
I need to get the value of the radio button, if the user selected Y or N. The Field names are going to be dynamically generated from id's in the database to form Radio Groups. When I try to <cfloop index="CurField" list="#form.fieldnames#"> to find the value of the radio button I will only get the value from the submit button.
Mike G.
If neither option is clicked, nothing will be in the form struct. Only if one of the options is selected will it show up.
jarofclay
The options are selected, I just don't know the name of the radio field to update the database because the name of the field will be different each time (<cfinput type="radio" name="#f5#" value="n">).
Mike G.
In addition to what jarofclay says, if one of the values must be provided, set the default option to have a `selected` attribute.
Peter Boughton
Also, instead of looping through, can you not just do this:`<input type="hidden" name="TheCheckboxIsCalled" value="#f5#"/>` ?
Peter Boughton
The options need to be optional.
Mike G.
Ok, please update the question to give full details of what you're trying to do and why you're trying to do it.
Peter Boughton
I have updated my original question with some more background, does this help?
Mike G.
A: 

Thank you all for your help, here was my final solution.

<cfif isDefined("FORM.bnt2")>
<cfloop index="id" list="#form.listofids#" delimiters=",">
<cfquery  name="accept" datasource="#request.dsn#">
UPDATE opt SET
F14 = '#Evaluate("form.select_#id#")#'
WHERE f5 = '#id#'
</cfquery>
</cfloop>
</cfif>


<cfform  name="frm2" id="form2" method="post" action="">
<cfoutput query="accountCheck" >
<cfinput type="radio" name="select_#f5#" value="y" required="yes" validateat="onsubmit" message="A value of Yes or No is required.">
<cfinput type="radio" name="select_#f5#" value="n" required="yes" validateat="onsubmit" message="A value of Yes or No is required.">
<cfinput type="hidden" name="listofids" value="#ValueList(accountCheck.f5)#" >
</cfoutput>
<cfinput name="bnt2" type="image" class="btn" src="images/accept.gif" value="x"  style="float:right;" />
</cfform>
Mike G.
Take another look at Peter Boughton's suggestions. There are several improvements you could make. Especially the note about cfqueryparam. BTW: Are you really storing SSN in a hidden field ..?
Leigh