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("
#i# - #arguments.form#
"); // 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"; //} } } } }
[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => zubair [ip] => zubair_hossain@ [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 5 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> looping over a structure using cfscript - Coldfusion - Advanced Techniques

looping over a structure using cfscript - Coldfusion - Advanced Techniques

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...

  1. #1

    Default 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

  2. #2

    Default 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

  3. #3

    Default 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

  4. #4

    Default 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

  5. #5

    Default 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

  6. #6

    Default 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

Similar Threads

  1. Replies: 1
    Last Post: May 1st, 03:24 PM
  2. Looping through a structure with duplicate key names
    By Fychan66 in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: June 13th, 11:47 AM
  3. cfscript
    By bikerboy in forum Coldfusion - Advanced Techniques
    Replies: 6
    Last Post: April 5th, 07:55 PM
  4. <cfscript> autocaps problem </cfscript> - betcha can't fix this!
    By CFMadness in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: March 23rd, 09:05 PM
  5. cfscript and variables
    By jhonken in forum Macromedia ColdFusion
    Replies: 0
    Last Post: March 3rd, 01:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •