Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
zubair #1
looping over a structure using cfscript
Hi,
I am passing form variables to a function. What i want is to be abled to loop
throught the form variables which is a structure and then for each value in the
structure do a trim.
I have something like this but i don't think it is right
for (i=1; i lte structcount(arguments.form); i=i+1 ) {
//writeoutput(arguments. & "<Br>");
// need to trim the current value
}
Cany anyone please help or point me in the right direction?
Thanks
zubair Guest
-
Class::Struct - want to access structure within structure
I want to access a structure within a structure. Below is what I had in mind. Please help. #!/perl/bin/perl use Class::Struct; struct Step... -
Looping through a structure with duplicate key names
It may be that I'm barking up the wrong tree here, and there's a nice function that will do this, but I want to turn an XML document returned to me... -
cfscript
since i cannot find the cf and java integration thread, gues i will post this here: i wrote a cfm with cfscript that utilizes java which connects... -
<cfscript> autocaps problem </cfscript> - betcha can't fix this!
First, I'll tell you up front that I am clueless when it comes to cfscript. So I apologize if this question is off topic. I have a nice little... -
cfscript and variables
I'm using cfscript against a COM object. In VB the paramater is passed like: Set oSegment = oTransactionset.CreateDataSegment('BEG')... -
PaulH #2
Re: looping over a structure using cfscript
you need a for in loop. be careful as you're going to get ALL of the form scope
(fieldnames, submit button, etc.) when you do this.
for (i IN arguments.form) {
writeoutput("#arguments.form[i]#<br>");
}
PaulH Guest
-
zubair #3
Re: looping over a structure using cfscript
Hi thanks for the reply. Is there also a way of deleting the fieldnames, submit
button etc attributes from the form struct as you mentioned? Also is it a case
of just using
trim(arguments.form)
to automatically trim all from variables?
Thanks
zubair Guest
-
PaulH #4
Re: looping over a structure using cfscript
you'd probably want to either copy the form scope to another structure (if
you're going to delete these using StructDelete function) or ignore them.
beyond the standard key for FIELDNAMES, everything else depends on your form.
no, you'll have to trim each value in the structure.
for (i IN arguments.form) {
if (i NEQ "FIELDNAMES")
writeoutput("#trim(arguments.form[i])#<br>");
}
PaulH Guest
-
zubair #5
Re: looping over a structure using cfscript
Thanks,
i'm doing this. Do you think this is a good way of doing it?
Thanks for your input
<!--- function to get the event and outcome dates --->
<cffunction name="trimVariables" access="public" output="Yes"
returntype="struct" hint="I trim whitespace of variables">
<cfargument name="form" required="Yes" type="struct">
<cfscript>
if ( StructIsEmpty(arguments.form) is 'NO' ) {
//writeoutput("form structure is not empty");
excludedFormElements = 'FIELDNAMES';
// loop through the form struct
for (i IN arguments.form) {
// make sure current key it structure being looped exists
if ( StructKeyExists(arguments.form, i) ) {
writeoutput("<br>#i# - #arguments.form#<br>");
// delete from the struct items in the
excludedFormElements list
if ( ListContains(excludedFormElements, i, ',') ) {
writeoutput("exclude this key");
temp = structdelete(arguments.form, i);
} else {
writeoutput("fine");
// trim variable
//arguments.form = "hi";
arguments.form = trim(arguments.form);
//if ( arguments.form eq 1 ) {
//arguments.form = "zzzzzzzz";
//}
}
}
}
}
</cfscript>
<cfreturn arguments.form>
</cffunction>
zubair Guest
-
CJM #6
looping over a structure using cfscript
You could delete the fieldnames key at the beginning of your code eliminating the re-occuring if statement.
<cfscript>
if ( structKeyExists(form,"fieldnames") structDelete(form,"fieldnames");
</cfscript>CJM Guest



Reply With Quote

