8 Replies Latest reply on Mar 11, 2007 1:48 AM by BKBK

    loop

    JohnGree Level 1
      Hi i have 5 text boxes which are named phone1, phone2 etc

      i need to run a loop through the code below to do the following

      1. evaluate to see if the form elements are empty
      2. if not empty get rid of spaces and leading zero
      3. once that is done loop through this code.

      i have this code to get rid of spaces and leading zero but how do add this to a loop for each text box?

      <cfif left(form.Phone1,1) EQ "0">
      <cfset PhoneNo =removeChars(replace(form.Phone1, " ", "", "all"),1,1)><cfelse>
      <cfset PhoneNo =form.Phone1>
      </cfif>
        • 1. Re: loop
          jdeline Level 1
          Your text box names are phone1, phone2, phone3, phone4 and phone5, right? Then the code below should get you started. The secret is to dynamically generate each phone variable.
          • 2. loop
            BKBK Adobe Community Professional & MVP
            You might want to play around with this. The result of interest is formStruct. I have included an example.



            • 3. Re: loop
              JohnGree Level 1
              Hi jdeline

              i have tried that but get an error of
              Variable PHONE is undefined.

              <CFLOOP INDEX="k" FROM="1" TO="5">
              <CFSET foo = phone & k>
              <CFIF foo IS NOT "">

              any ideas?
              • 4. Re: loop
                BKBK Adobe Community Professional & MVP
                typo: "phone"

                • 5. loop
                  JohnGree Level 1
                  ok i am now using your version, i have a cfmail which i need inside the loop but the variable do i need to email each phone1, phone 2 etc

                  ie

                  <cfmail
                  to = "emai"
                  from = "email"
                  subject = "test">

                  #formStruct#

                  </cfmail>
                  • 6. loop
                    BKBK Adobe Community Professional & MVP
                    The (edited) example says it.

                    whether or not form field phone3 was empty: formStruct.phone3.isFilled
                    number entered (that is, form.phone3): formStruct.phone3.number

                    <cfmail
                    to = "email"
                    from = "email"
                    subject = "test">

                    Hi #firstName#,

                    <cfif formStruct.phone3.isFilled>
                    Thanks for sending us your phone number. To confirm, your GSM number is #formStruct.phone3.number#.
                    <cfelse>
                    Please send us your GSM number so that we can inform you of new offers.
                    </cfif>

                    </cfmail>


                    • 7. Re: loop
                      JohnGree Level 1
                      ok i have tried that but get an error

                      Element PHONE3.NUMBER is undefined in FORMSTRUCT

                      what i need is if 4 of the 5 text boxes (phone1,2,3,4,5) are not empty send a email 4 times with the different phone number in each

                      do i need to have 5 different cfmails?
                      • 8. Re: loop
                        BKBK Adobe Community Professional & MVP
                        It only takes a minor addition to the code, thus