Copier le lien dans le Presse-papiers
Copié
Hi All,
I haven't used coldfusion for a while and I am a little stuck getting my head around a problem I have occured. I have taken a project over from one of my colleagues so the coding is not my own. See code below....
<cfif isdefined("btnSubmit")>
<!--- DO INDIVIDUAL UPDATE CODE HERE --->
</cfif>
<cfoutput query="getList">
<cfform name="fmUpdList99_#applicationid#" action="list99.cfm">
Clear: <cfinput type="Radio" name="result" checked="No" value="CLEAR">
Match: <cfinput type="Radio" name="result" checked="No" value="MATCH">
N/A: <cfinput type="Radio" name="result" checked="No" value="NA">
<input type="submit" name="btnSubmit" value="Save" />
</cfform>
</cfoutput>
Now this works perfectly if I want to click on a submit button per row and save each row individually.... But what the user wants is the option to have a save all button which loops through each row and does the update code for all rows (rather than individually) depending on what is selected in the radio buttons.
Sorry if I haven't described my problem to well, its just I haven't used CF for a while now and trying my best to get back into it.
All apprciate all the help you can give.
Thanks,
George
The variable name #form["result"&ilist99id]# should look something like this form.result12345 when concatinated.
Right. So which part is the struct, and which part is the key?
Note that the key value for structKeyExists() is a STRING... so...it can be able expression that evaluates to a string.
"result"&ilist99id
This is a string, isn't it...?
So...
... what does structKeyExists(form, "result"&ilist99id) give you?
--
Adam
Copier le lien dans le Presse-papiers
Copié
P.s Dont think I made it clear, I need the option to have a 'save all' aswell as to save individually also.
Copier le lien dans le Presse-papiers
Copié
I do that sort of thing like this:
On the form page:
<cfoutput query="something">
<input name = static_part#dynamic_part#>
on the results page.
<cfloop list = "#form.fieldnames#" index = ThisField>
<cfif left(ThisField, 11) is static_part>
<cfset ThisID = RemoveChars(ThisField, 1, 11>
<cfset ThisValue = form[ThisField]>
then process as required.
Copier le lien dans le Presse-papiers
Copié
Thanks for your reply Dan... Although this works when I want a save all button, but wont work if I want to save each individually also. Any other suggesions ?
Copier le lien dans le Presse-papiers
Copié
P.s I have another question.. how do I do an isdefined on this variable ? #form["result"&ilist99id]#
Copier le lien dans le Presse-papiers
Copié
You don't. You use structKeyExists(). Avoid isDefined() if poss, as it's a bit of a hangover from pre CFMX days.
--
Adam
Copier le lien dans le Presse-papiers
Copié
Why do you think that?
Copier le lien dans le Presse-papiers
Copié
Thanks guys, I apprciate the help.
How would I syntax it to use my variable: #form["result"&ilist99id]# to use in conjuction with the method StructKeyExists ???
Dan - No worrys about the previous question, have managed to fix it. thanks.
Copier le lien dans le Presse-papiers
Copié
How would I syntax it to use my variable: #form["result"&ilist99id]# to use in conjuction with the method StructKeyExists ???
What did you try, and what were the results?
Did you have a look @ the docs:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fbb.html
Did they not make sense?
This is the key text from the docs:
StructKeyExists(structure, "key")
Parameter | Description |
|---|---|
structure | Name of structure to test |
key | Key to test |
This function can sometimes be used in place of the IsDefined function, when working with the URL and Form scopes, which are structures. The following pieces of code are equivalent:
cfif IsDefined("Form.JediMaster")>
<cfif StructKeyExists(Form,"JediMaster")>I suspect Ray Camden wrote this part of the docs... 😉
So given all that... how would you use structKeyExists()?
The chief questions are:
* which part of your variable is the structure?
* which part of your variable is the key?
--
Adam
Copier le lien dans le Presse-papiers
Copié
Well... It is a form variable that has been submitted from my form. But it is a dynamic variable which is causing my trouble and how to syntax it.
The variable name #form["result"&ilist99id]# should look something like this form.result12345 when concatinated.
Copier le lien dans le Presse-papiers
Copié
The variable name #form["result"&ilist99id]# should look something like this form.result12345 when concatinated.
Right. So which part is the struct, and which part is the key?
Note that the key value for structKeyExists() is a STRING... so...it can be able expression that evaluates to a string.
"result"&ilist99id
This is a string, isn't it...?
So...
... what does structKeyExists(form, "result"&ilist99id) give you?
--
Adam
Copier le lien dans le Presse-papiers
Copié
Thank you Adam that worked a treat!
Copier le lien dans le Presse-papiers
Copié
Cool.
Sorry to be a bit circuitous in getting there, but I figure - whether the other person wants me to or not 😉 - it's better to guide them towards how to suss the answer out for themselves, rather than me just blurting out the answer...
--
Adam
Copier le lien dans le Presse-papiers
Copié
Now that you have your answer regarding StructKeyExists, I'm curious as to why you think you need to use it.
Copier le lien dans le Presse-papiers
Copié
Why ? Because it is not a required field so when I submit the form (which redirects to same page as form) it is not defined and it throws an error. With StructKeyExists, this helps me catch this.
Copier le lien dans le Presse-papiers
Copié
That being the case, you might consider doing only one check to see whether or not you are processing a form. It will simplify your code and make your page run faster.
Préparez-vous ! Une expérience Adobe Community améliorée arrive en janvier.
En savoir plus