8 Replies Latest reply on Feb 18, 2007 4:57 PM by Newsgroup_User

    cfif select option value problem

    Level 7
      I have a form with a dropdown box asking users to select where they
      heard about my site. The completed form sent to me via email.

      The dropdown is optional so if they don't select it I would like nothing
      to be returned in the email.

      The first option reads "I heard about you from" - I've tried <option
      value> <option value=""> and even <cfselect> with various options but I
      can't get it to work.

      This is what I have for the email:

      <cfif isdefined("form.referral")><cfoutput>#form.senderFirst# heard
      about you from #form.referral#</cfoutput></cfif>

      This is what I have for the select options:

      <select name="referral">
      <option value="">I heard about you from...</option>
      <option value="Google">Google</option>
      <option value="Yahoo!">Yahoo!</option>
      <option value="Ask">Ask</option>
      <option value="MSN">MSN</option>
      <option value="a friend">A friend</option>
      <option value="somewhere else">Somewhere else</option>
      </select>
        • 1. Re: cfif select option value problem
          dempster Level 1
          Why not use something like <option value="X"> and then test this way:

          <cfif isdefined("form.referral") AND form.referral NEQ "X">
          <cfoutput>#form.senderFirst# heard about you from #form.referral#</cfoutput>
          </cfif>
          • 2. Re: cfif select option value problem
            Level 7
            dempster wrote:
            > Why not use something like <option value="X"> and then test this way:
            >
            > <cfif isdefined("form.referral") AND form.referral NEQ "X">
            > <cfoutput>#form.senderFirst# heard about you from #form.referral#</cfoutput>
            > </cfif>

            Thanks dempster that worked!

            Now I'd like to be able to do the same thing to a phone text box, a few
            checkboxes and a textarea.

            None of the code below works - they all return messages (i.e. "Phone:"
            "Interested in:" and "Message:") even if that field isn't filled out.
            I've tried several different variables with no success.

            My questions are:

            1. Phone - How can I write the cfif so the "Phone:" doesn't appear in
            the email if a phone number isn't entered?

            2. Checkboxes - The problem here isn't with the boxes themselves, but
            with the "Interested in. Currently I have it set to "WebSiteDesign". The
            obvious problem here occurs when they check another box, such as
            "GraphicDesign". I've tried OR statements with no success. How can I
            write a cfif for the exclusion of "Interested in" in the email if no
            checkboxes are selected?

            3. Textarea - What do I need to change in order for the email not to
            display "Message:" if no message is entered?

            Here's the code:

            PHONE

            <!---Appears in the email--->

            <cfif IsDefined ("form.senderPhone")>
            <p>Phone: <cfoutput>#form.senderPhone#</cfoutput></p>
            </cfif>

            <!---Appears on the page--->

            <cfinput type="Text"
            name="senderPhone"
            message="Please enter your area code and phone number."
            mask="999-999-9999"
            validate="telephone"
            validateat="onsubmit,onserver"
            size="30"
            maxlength="16">




            CHECKBOXES

            <!---Appears in the email--->

            <cfif IsDefined("form.webSiteDesign")>
            <p>Interested in:</p>
            </cfif>

            <ol>
            <cfif isdefined("form.webSiteDesign")>
            <li>Web site design</li>
            </cfif>
            <cfif isdefined("form.graphicDesign")>
            <li>Graphic design</li>
            </cfif>
            <cfif isdefined("form.logoDesign")>
            <li>Logo design</li>
            </cfif>
            </ol>


            <!---Appears on the page--->

            <p class="boxes">
            <cfinput type="checkbox" name="webSiteDesign" value="yes">
            Web site design</p>

            <p class="boxes">
            <cfinput type="checkbox" name="graphicDesign" value="yes">
            Graphic design</p>

            <p class="boxes">
            <cfinput type="checkbox" name="logoDesign" value="yes">
            Logo design</p>




            TEXTAREA

            <!---Appears in the email--->

            <cfif IsDefined("form.senderMessage")>
            <p>Message:
            <cfoutput>#ParagraphFormat(form.senderMessage)#</cfoutput></p>
            </cfif>


            <!---Appears on the page--->

            <textarea name="senderMessage" cols="44" rows="6" wrap="virtual">
            </textarea>
            • 3. Re: cfif select option value problem
              BKBK Adobe Community Professional & MVP
              <p>
              I heard about you from: <br>
              <cfselect name="referral">
              <option value=" " selected></option>
              <option value="Google">Google</option>
              <option value="Yahoo!">Yahoo!</option>
              <option value="Ask">Ask</option>
              <option value="MSN">MSN</option>
              <option value="friend">A friend</option>
              <option value="elsewhere">Somewhere else</option>
              </cfselect>
              </p>

              • 4. Re: cfif select option value problem
                Level 7
                Radio buttons and checkboxes are the only form elements that do not have a default value, so the others will always be defined.

                <cfif IsDefined ("form.senderPhone") AND Len(Trim(FORM.senderPhone)) GT 0>
                <p>Phone: <cfoutput>#form.senderPhone#</cfoutput></p>
                </cfif>

                <cfif IsDefined("form.senderMessage") AND Len(Trim(FORM.senderMessage)) GT 0>
                <p>Message:
                <cfoutput>#ParagraphFormat(form.senderMessage)#</cfoutput>
                </p>
                </cfif>

                Probably a more elegant way to do this but I can't think of it right now.

                <cfparam name="FORM.webSiteDesign" default="no">
                <cfparam name="FORM.graphicDesign" default="no">
                <cfparam name="FORM.logoDesign" default="no">
                <cfif FORM.webSiteDesign EQ "yes" OR FORM.graphicDesign EQ "yes" OR FORM.logoDesign EQ "yes">
                <p>
                Interested in:<br>
                <cfif FORM.webSiteDesign EQ "yes">
                webSiteDesign <br>
                </cfif>
                <cfif FORM.graphicDesign EQ "yes">
                graphicDesign<br>
                </cfif>
                <cfif FORM.logoDesign EQ "yes">
                logoDesign<br>
                </cfif>
                </p>
                </cfif>


                --
                Ken Ford
                Adobe Community Expert
                Fordwebs, LLC
                http://www.fordwebs.com


                "ryansebiz" <ryanjburnett@no-spam-gmail.com> wrote in message news:eraat2$qrn$1@forums.macromedia.com...
                > dempster wrote:
                >> Why not use something like <option value="X"> and then test this way:
                >>
                >> <cfif isdefined("form.referral") AND form.referral NEQ "X">
                >> <cfoutput>#form.senderFirst# heard about you from #form.referral#</cfoutput>
                >> </cfif>
                >
                > Thanks dempster that worked!
                >
                > Now I'd like to be able to do the same thing to a phone text box, a few
                > checkboxes and a textarea.
                >
                > None of the code below works - they all return messages (i.e. "Phone:"
                > "Interested in:" and "Message:") even if that field isn't filled out.
                > I've tried several different variables with no success.
                >
                > My questions are:
                >
                > 1. Phone - How can I write the cfif so the "Phone:" doesn't appear in
                > the email if a phone number isn't entered?
                >
                > 2. Checkboxes - The problem here isn't with the boxes themselves, but
                > with the "Interested in. Currently I have it set to "WebSiteDesign". The
                > obvious problem here occurs when they check another box, such as
                > "GraphicDesign". I've tried OR statements with no success. How can I
                > write a cfif for the exclusion of "Interested in" in the email if no
                > checkboxes are selected?
                >
                > 3. Textarea - What do I need to change in order for the email not to
                > display "Message:" if no message is entered?
                >
                > Here's the code:
                >
                > PHONE
                >
                > <!---Appears in the email--->
                >
                > <cfif IsDefined ("form.senderPhone")>
                > <p>Phone: <cfoutput>#form.senderPhone#</cfoutput></p>
                > </cfif>
                >
                > <!---Appears on the page--->
                >
                > <cfinput type="Text"
                > name="senderPhone"
                > message="Please enter your area code and phone number."
                > mask="999-999-9999"
                > validate="telephone"
                > validateat="onsubmit,onserver"
                > size="30"
                > maxlength="16">
                >
                >
                >
                >
                > CHECKBOXES
                >
                > <!---Appears in the email--->
                >
                > <cfif IsDefined("form.webSiteDesign")>
                > <p>Interested in:</p>
                > </cfif>
                >
                > <ol>
                > <cfif isdefined("form.webSiteDesign")>
                > <li>Web site design</li>
                > </cfif>
                > <cfif isdefined("form.graphicDesign")>
                > <li>Graphic design</li>
                > </cfif>
                > <cfif isdefined("form.logoDesign")>
                > <li>Logo design</li>
                > </cfif>
                > </ol>
                >
                >
                > <!---Appears on the page--->
                >
                > <p class="boxes">
                > <cfinput type="checkbox" name="webSiteDesign" value="yes">
                > Web site design</p>
                >
                > <p class="boxes">
                > <cfinput type="checkbox" name="graphicDesign" value="yes">
                > Graphic design</p>
                >
                > <p class="boxes">
                > <cfinput type="checkbox" name="logoDesign" value="yes">
                > Logo design</p>
                >
                >
                >
                >
                > TEXTAREA
                >
                > <!---Appears in the email--->
                >
                > <cfif IsDefined("form.senderMessage")>
                > <p>Message:
                > <cfoutput>#ParagraphFormat(form.senderMessage)#</cfoutput></p>
                > </cfif>
                >
                >
                > <!---Appears on the page--->
                >
                > <textarea name="senderMessage" cols="44" rows="6" wrap="virtual">
                > </textarea>
                • 5. Re: cfif select option value problem
                  dempster Level 1
                  It helps to have an understanding of how CGI passes form fields, but basically text input fields and textareas pass a value even if it is an empty string. So the easiest way to check is just look at the length of the field, for example:

                  <CFIF Len(form.senderMessage) GT 0>
                  Message: #form.senderMessage#
                  </CFIF>
                  • 6. Re: cfif select option value problem
                    dempster Level 1
                    Sorry, I overlooked your checkbox question. Two ways to handle this. One is just to extend your CFIF with OR:

                    <CFIF IsDefined("form.webSiteDesign") OR IsDefined("form.graphicDesign") IsDefined("form.logoDesign")>

                    The other way is to give the checkboxes the same name and different values:

                    <INPUT TYPE="checkbox" NAME="interests" VALUE="Web Site Design">Web Site Design
                    <INPUT TYPE="checkbox" NAME="interests" VALUE="Graphic Design">Graphic Design
                    <INPUT TYPE="checkbox" NAME="interests" VALUE="Logo Design">Logo Design

                    In this approach, you can see if Form.interests is defined, then loop through the values as a comma-delimited list.

                    <CFIF IsDefined("Form.interests")>
                    Interested in:
                    <UL>
                    <CFLOOP INDEX="oneinterest" LIST="#Form.interests#">
                    <LI>#oneinterest#</LI>
                    </CFLOOP>
                    </UL>
                    </CFIF>

                    The advantage of this approach is that it's easy to modify by just changing the form.
                    • 7. Re: cfif select option value problem
                      Level 7
                      Ken Ford - *ACE* wrote:
                      > Radio buttons and checkboxes are the only form elements that do not have
                      > a default value, so the others will always be defined.
                      >
                      > <cfif IsDefined ("form.senderPhone") AND Len(Trim(FORM.senderPhone)) GT 0>
                      > <p>Phone: <cfoutput>#form.senderPhone#</cfoutput></p>
                      > </cfif>

                      Thanks Ken - that worked perfectly! The Trim function is especially
                      appreciated.

                      > Probably a more elegant way to do this but I can't think of it right now.

                      See dempster's <cfloop> checkbox answer below. Extremely elegant to say
                      the least :)
                      • 8. Re: cfif select option value problem
                        Level 7
                        dempster wrote:
                        > The other way is to give the checkboxes the same name and different values:
                        >
                        > <INPUT TYPE="checkbox" NAME="interests" VALUE="Web Site Design">Web Site Design
                        > <INPUT TYPE="checkbox" NAME="interests" VALUE="Graphic Design">Graphic Design
                        > <INPUT TYPE="checkbox" NAME="interests" VALUE="Logo Design">Logo Design
                        >
                        > In this approach, you can see if Form.interests is defined, then loop through
                        > the values as a comma-delimited list.
                        >
                        > <CFIF IsDefined("Form.interests")>
                        > Interested in:
                        >

                        • > <CFLOOP INDEX="oneinterest" LIST="#Form.interests#">
                          >
                        • #oneinterest#</LI>
                          > </CFLOOP>
                          >

                        > </CFIF>
                        >
                        > The advantage of this approach is that it's easy to modify by just changing
                        > the form.

                        Wow. Just wow. That was exactly what I was looking for and then some.

                        Now I only have to change the checkboxes to update the form. Brilliant.

                        Thanks a million dempster!