4 Replies Latest reply on Jul 4, 2007 12:06 AM by BKBK

    Advanced form programming/ Please help

    Irish-Phoenix Level 1
      I am trying to write a form for my web site. I don't want to use the standard form tags in ColdFusion that make you have to fil in fields before the form will submit.

      EX:
      <cfform action="SENDMAIL.cfm" method="post" enablecab="no" name="request" enctype="application/x-www-form-urlencoded">



      I want it to check it's self then if all fields are defined, then send it off to the sendmail form. So it is 2 pages. this is more of what I am after here:

      EX2:
      <cfif Fname ISdefined>
      <cfform action="SENDMAIL.cfm" method="post" enablecab="no" name="request" enctype="application/x-www-form-urlencoded">

      <font face="Verdana, Arial, Helvetica, sans-serif" font color="#000000" size="1"><b><strong>First Name:</strong></font>
      <cfinput name="Fname" type="text" size="32" maxlength="32">
      </cfform>
      <cfelse>
      <cfform action="SENDMAIL.cfm" method="post" enablecab="no" name="request" enctype="application/x-www-form-urlencoded">

      <font face="Verdana, Arial, Helvetica, sans-serif" font color="#000000" size="1"><b><strong>First Name:</strong></font>
      <font face="Verdana, Arial, Helvetica, sans-serif" font color="#990000" size="1">*</font><cfinput name="Fname" type="text" size="32" maxlength="32">
      </cfif>

      This option doesn't work, but it is the way I am trying to get it to work.

      If a person goes through the form, and misses lets say their name, it will not submit the form, but red text will appear next to the missing fields. Making them fil it in. Not using the pop up that you get when using the standard CF code. How do I do this? I need it to work for multiple fields, not just one.

      Can anyone show me the code to make this kind of foorm work?

      Thank you.

      Phoenix
        • 1. Re: Advanced form programming/ Please help
          BKBK Adobe Community Professional & MVP
          If a person goes through the form, and misses lets say their name, it will not submit the form, but red text will appear next to the missing fields.

          Coldfusion forms already have that functionality built in. Two examples are

          <cfform action="#cgi.script_name#" method="post">
          user-name: <cfinput type="text" name="username" required="yes" message="You must enter your user-name"><br>
          <cfinput type="submit" name="sbmt" value="CheckIt">
          </cfform>

          <cfoutput><form action="#cgi.script_name#" method="post"></cfoutput>
          user-name: <input type="text" name="username">
          <Input type="hidden" name="username_required" value="You must enter your user-name"><br>
          <input type="submit" name="sbmt" value="CheckIt">
          </form>


          • 2. Re: Advanced form programming/ Please help
            Irish-Phoenix Level 1
            I realize ColdFusion has these codes set, but I also want to add code to test the validity of email addresses.

            <CFSET EMail = Attributes.EMail>

            <CFIF #EMail# is "">
            <CFSET #Caller.EMail_Level# = "1">
            <CFSET #Caller.EMail_Message# = "No e-mail address was supplied.">
            <CFELSEIF #FindNoCase('@',EMail)# is 0>
            <CFSET #Caller.EMail_Level# = "2">
            <CFSET #Caller.EMail_Message# = "No @ sign detected. An @ sign is part of every e-mail address.">
            <CFELSEIF #Right(EMail,1)# is "@">
            <CFSET #Caller.EMail_Level# = "3">
            <CFSET #Caller.EMail_Message# = "An @ sign cannot be the last character of the e-mail address.">
            <CFELSEIF #Left(EMail,1)# is "@">
            <CFSET #Caller.EMail_Level# = "4">
            <CFSET #Caller.EMail_Message# = "An @ sign cannot be the first character of the e-mail address.">
            <CFELSEIF #FindNoCase('@',EMail,(FindNoCase('@',EMail) + 1))# is not 0>
            <CFSET #Caller.EMail_Level# = "5">
            <CFSET #Caller.EMail_Message# = "A valid e-mail address contains only one @ sign.">
            <CFELSEIF #FindNoCase('.',Email)# is 0>
            <CFSET #Caller.EMail_Level# = "6">
            <CFSET #Caller.EMail_Message# = "No period detected. An e-mail address contains at least one period.">
            <CFELSEIF #Right(EMail,1)# is ".">
            <CFSET #Caller.EMail_Level# = "7">
            <CFSET #Caller.EMail_Message# = "The last character of the e-mail address cannot be a period.">
            <CFELSEIF #Left(EMail,1)# is ".">
            <CFSET #Caller.EMail_Level# = "8">
            <CFSET #Caller.EMail_Message# = "The first character of the e-mail address cannot be a period.">
            <CFELSEIF #FindNoCase(',',EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "9">
            <CFSET #Caller.EMail_Message# = "A valid e-mail address cannot contain a comma. If you have a Compuserve account, substitute a period for the comma in your Compuserve ID, like so: <B>12345.6789@compuserve.com</B>.">
            <CFELSEIF #FindNoCase(' ',EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "10">
            <CFSET #Caller.EMail_Message# = "You cannot have a space as part of a single e-mail address.">
            <CFELSEIF #FindNoCase('*',EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "11">
            <CFSET #Caller.EMail_Message# = "You cannot have an asterisk in an e-mail address.">
            <CFELSEIF #FindNoCase(')',EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "12">
            <CFSET #Caller.EMail_Message# = "You cannot have a close parenthesis sign in an e-mail address.">
            <CFELSEIF #FindNoCase('(',EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "13">
            <CFSET #Caller.EMail_Message# = "You cannot have an open parenthesis sign in an e-mail address.">
            <CFELSEIF #FindNoCase(CHR(62),EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "14">
            <CFSET #Caller.EMail_Message# = "You cannot have a greater than sign in an e-mail address.">
            <CFELSEIF #FindNoCase(CHR(60),EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "15">
            <CFSET #Caller.EMail_Message# = "You cannot have a less than sign in an e-mail address.">
            <CFELSEIF #FindNoCase(':',EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "16">
            <CFSET #Caller.EMail_Message# = "You cannot have a colon in an e-mail address.">
            <CFELSEIF #FindNoCase(';',EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "17">
            <CFSET #Caller.EMail_Message# = "You cannot have a semicolon in an e-mail address.">
            <CFELSEIF #FindNoCase(CHR(34),EMail)# is not 0>
            <CFSET #Caller.EMail_Level# = "18">
            <CFSET #Caller.EMail_Message# = "You cannot have a double quote in an e-mail address.">
            <CFELSE>
            <CFSET #Caller.EMail_Level# = "0">
            <CFSET #Caller.EMail_Message# = "Good e-mail address.">
            </CFIF>

            So would I have to make the form 2 pages to make it do what I want it to do? How would I add this code to a one page form, and send it off to the sendmail part of the form?

            Thank you.

            Phoenix
            • 3. Re: Advanced form programming/ Please help
              Kronin555 Level 1
              <cfinput type="email" name="emailaddress" required="yes" validate="regular_expression" pattern="^.+@[^\.].*\.[a-z]{2,}$" message="You must enter a valid email address (me@mydomain.com, for example)">
              • 4. Re: Advanced form programming/ Please help
                BKBK Adobe Community Professional & MVP
                The above suggestions take care of client-side validation. For the server-side validation you really don't need to go into details, as you've done.

                Your custom tag can make use of Coldfusion's isValid function. Here is an example of a calling page and custom tag page.