ASP required fileds in E-mail form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Creelman

    ASP required fileds in E-mail form



    Hi:

    I am relatively new to ASP. I prefer Perl, but need to do this form to e-mail sipt for a web page,

    See Example of script below that works fine. I want to add the feature to this where it will tell customer that they missed a field, "click
    here" to go back & try again.

    Does not need to be fancy telling them which field they missed. (Although would be nice) Can even require all fields to be filled out, or do again.
    Currently it kicks you out when e-mail field is empty, but not on any other field.

    Again..nothing fancy need be written, just the basics.


    Any help would be appreciated.

    Thanks,
    Mark
    ---------------------------------------------------------------------------------

    <%

    On Error Resume Next

    If Request.Form("s end") <> "" Then
    Set iConf = CreateObject ("CDO.Configura tion")
    Set Flds = iConf.Fields


    Flds(cdoSendUsi ngMethod) = cdoSendUsingPor t
    Flds(cdoSMTPSer ver) = "mail.korax.net "
    Flds.Update

    Set iMesg = CreateObject("C DO.Message")
    Set iMesg.Configura tion = iConf

    Err.Clear

    iMesg.To = "me@mymail. com"
    iMesg.From = Request.Form("E mail")
    iMesg.Subject = "Email Form"


    str1 = Request.Form("F name")
    str2 = Request.Form("L name")
    str3 = Request.Form("E mail")


    iMesg.TextBody = str1 & " " & str2 & str3


    iMesg.Send

    If Err.Number = 0 Then
    Result = ""
    Response.Redire ct "http://mydomain.com/thankyou.htm"
    Else
    Result = "You didn't enter your E-mail address"
    End If
    End If


    %>


    <body bgcolor="#3E71A 8" topmargin="0" leftmargin="0" marginheight="0 " marginwidth="0" >
    <!--metadata type="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" name="CDO for Windows 2000 Type Library" -->


    <form method=post>


    <table border="0" cellspacing="0" cellpadding="2" width="581">

    <td align="right" valign="middle" class="smain" width="192"><fo nt color="red"><b> *</b></font>&nbsp;Firs t:&nbsp;</td>
    <td align="left" valign="middle" class="smain" width="119"><in put type="text" name="FName" size="15" maxlength="20" tabindex="2" ID="Text1"></td>
    <td align="left" valign="middle" width="1">&nbsp ;</td>
    <td align="right" valign="middle" class="smain" width="185"><fo nt color="red"><b> *</b></font>&nbsp;Last :&nbsp;</td>
    <td align="left" valign="middle" class="smain" width="185"><in put type="text" name="LName" size="15" maxlength="20" tabindex="3" ID="Text2"></td>

    <td align="left" valign="middle" class="smain" width="185"><in put type="text" name="Email" size="15" maxlength="20" tabindex="3" ID="Text3"></td>


    </tr>

    </table>


    </form>


  • Ray Costanzo [MVP]

    #2
    Re: ASP required fileds in E-mail form

    The simplest approach is:


    sSomeValue = Request.Form("f ormField")
    If Trim(sSomeValue ) = "" Then
    Response.Write "You missed a field. Hit your back button."
    Response.End
    End If

    Ray at home

    "Mark Creelman" <rdcomp@sympati co.ca> wrote in message
    news:4b5fo01uqn usc36dj0mip7gk9 k9pbq5glv@4ax.c om...[color=blue]
    >
    >
    > Hi:
    >
    > I am relatively new to ASP. I prefer Perl, but need to do this form to
    > e-mail sipt for a web page,
    >
    > See Example of script below that works fine. I want to add the feature to
    > this where it will tell customer that they missed a field, "click
    > here" to go back & try again.
    >
    > Does not need to be fancy telling them which field they missed. (Although
    > would be nice) Can even require all fields to be filled out, or do again.
    > Currently it kicks you out when e-mail field is empty, but not on any
    > other field.
    >
    > Again..nothing fancy need be written, just the basics.
    >
    >
    > Any help would be appreciated.
    >
    > Thanks,
    > Mark
    > ---------------------------------------------------------------------------------
    >
    > <%
    >
    > On Error Resume Next
    >
    > If Request.Form("s end") <> "" Then
    > Set iConf = CreateObject ("CDO.Configura tion")
    > Set Flds = iConf.Fields
    >
    >
    > Flds(cdoSendUsi ngMethod) = cdoSendUsingPor t
    > Flds(cdoSMTPSer ver) = "mail.korax.net "
    > Flds.Update
    >
    > Set iMesg = CreateObject("C DO.Message")
    > Set iMesg.Configura tion = iConf
    >
    > Err.Clear
    >
    > iMesg.To = "me@mymail. com"
    > iMesg.From = Request.Form("E mail")
    > iMesg.Subject = "Email Form"
    >
    >
    > str1 = Request.Form("F name")
    > str2 = Request.Form("L name")
    > str3 = Request.Form("E mail")
    >
    >
    > iMesg.TextBody = str1 & " " & str2 & str3
    >
    >
    > iMesg.Send
    >
    > If Err.Number = 0 Then
    > Result = ""
    > Response.Redire ct "http://mydomain.com/thankyou.htm"
    > Else
    > Result = "You didn't enter your E-mail address"
    > End If
    > End If
    >
    >
    > %>
    >
    >
    > <body bgcolor="#3E71A 8" topmargin="0" leftmargin="0" marginheight="0 "
    > marginwidth="0" >
    > <!--metadata type="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
    > name="CDO for Windows 2000 Type Library" -->
    >
    >
    > <form method=post>
    >
    >
    > <table border="0" cellspacing="0" cellpadding="2" width="581">
    >
    > <td align="right" valign="middle" class="smain" width="192"><fo nt
    > color="red"><b> *</b></font>&nbsp;Firs t:&nbsp;</td>
    > <td align="left" valign="middle" class="smain" width="119"><in put
    > type="text" name="FName" size="15" maxlength="20" tabindex="2"
    > ID="Text1"></td>
    > <td align="left" valign="middle" width="1">&nbsp ;</td>
    > <td align="right" valign="middle" class="smain" width="185"><fo nt
    > color="red"><b> *</b></font>&nbsp;Last :&nbsp;</td>
    > <td align="left" valign="middle" class="smain" width="185"><in put
    > type="text" name="LName" size="15" maxlength="20" tabindex="3"
    > ID="Text2"></td>
    >
    > <td align="left" valign="middle" class="smain" width="185"><in put
    > type="text" name="Email" size="15" maxlength="20" tabindex="3"
    > ID="Text3"></td>
    >
    >
    > </tr>
    >
    > </table>
    >
    >
    > </form>
    >
    >[/color]


    Comment

    • Stephanie Stowe

      #3
      Re: ASP required fileds in E-mail form

      What I would do is:

      1. Provide JavaScript client-side so that they do not have to make a return
      trip to the server. See example:
      http://examples.oreilly.com/jscript3/text/16-2.txt (You will have to view
      source since this particular example's View Source is not formatted
      correctly.

      2. Provide server side validation in case the user has client side disabled
      or whatever. What I would do is avoid the click here to return is post
      directly back to the same page. <form method=post> with no action or <form
      method=post action="login.a sp"> where login.asp is the same page.

      Quick hack for demonstration purposes:

      <%


      dim strMessage, blnError


      blnError = false
      if Request.Form("s ubmit") <> "" then ' being posted back
      if request.Form("e mail") = "" then
      strMessage = "Email field is required." & "<BR>"
      blnError = true
      end if

      '' whatever other fields you want
      if Not blnError then
      response.Redire ct "ToDo.htm"
      end if

      end if

      %>

      <html>
      <head>
      <title>test</title>
      <meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
      <meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
      <meta name=vs_default ClientScript content="JavaSc ript">
      <meta name=vs_targetS chema
      content="http://schemas.microso ft.com/intellisense/ie3-2nav3-0">
      </head>
      <body MS_POSITIONING= "FlowLayout ">

      <%

      if blnError then
      response.Write "<P><font color=red>" & strMessage & "</font></P>"
      end if
      %>
      <form id="Form1" method="post">
      <TABLE WIDTH="90%" BORDER="1" CELLSPACING="3" CELLPADDING="3" >
      <TR>
      <TD>Email</TD>
      <TD><input type=text name=email><fon t color=red>*</font></TD>
      </TR>
      <TR>
      <TD>Name</TD>
      <TD><input type=text name=yourname</TD>
      </TR>
      <TR>
      <TD colspan=2><inpu t type=submit value=submit name=submit></TD>

      </TR>
      </TABLE>


      </form>

      </body>
      </html>


      "Mark Creelman" <rdcomp@sympati co.ca> wrote in message
      news:4b5fo01uqn usc36dj0mip7gk9 k9pbq5glv@4ax.c om...[color=blue]
      >
      >
      > Hi:
      >
      > I am relatively new to ASP. I prefer Perl, but need to do this form to[/color]
      e-mail sipt for a web page,[color=blue]
      >
      > See Example of script below that works fine. I want to add the feature to[/color]
      this where it will tell customer that they missed a field, "click[color=blue]
      > here" to go back & try again.
      >
      > Does not need to be fancy telling them which field they missed. (Although[/color]
      would be nice) Can even require all fields to be filled out, or do again.[color=blue]
      > Currently it kicks you out when e-mail field is empty, but not on any[/color]
      other field.[color=blue]
      >
      > Again..nothing fancy need be written, just the basics.
      >
      >
      > Any help would be appreciated.
      >
      > Thanks,
      > Mark
      > --------------------------------------------------------------------------[/color]
      -------[color=blue]
      >
      > <%
      >
      > On Error Resume Next
      >
      > If Request.Form("s end") <> "" Then
      > Set iConf = CreateObject ("CDO.Configura tion")
      > Set Flds = iConf.Fields
      >
      >
      > Flds(cdoSendUsi ngMethod) = cdoSendUsingPor t
      > Flds(cdoSMTPSer ver) = "mail.korax.net "
      > Flds.Update
      >
      > Set iMesg = CreateObject("C DO.Message")
      > Set iMesg.Configura tion = iConf
      >
      > Err.Clear
      >
      > iMesg.To = "me@mymail. com"
      > iMesg.From = Request.Form("E mail")
      > iMesg.Subject = "Email Form"
      >
      >
      > str1 = Request.Form("F name")
      > str2 = Request.Form("L name")
      > str3 = Request.Form("E mail")
      >
      >
      > iMesg.TextBody = str1 & " " & str2 & str3
      >
      >
      > iMesg.Send
      >
      > If Err.Number = 0 Then
      > Result = ""
      > Response.Redire ct "http://mydomain.com/thankyou.htm"
      > Else
      > Result = "You didn't enter your E-mail address"
      > End If
      > End If
      >
      >
      > %>
      >
      >
      > <body bgcolor="#3E71A 8" topmargin="0" leftmargin="0" marginheight="0 "[/color]
      marginwidth="0" >[color=blue]
      > <!--metadata type="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"[/color]
      name="CDO for Windows 2000 Type Library" -->[color=blue]
      >
      >
      > <form method=post>
      >
      >
      > <table border="0" cellspacing="0" cellpadding="2" width="581">
      >
      > <td align="right" valign="middle" class="smain" width="192"><fo nt[/color]
      color="red"><b> *</b></font>&nbsp;Firs t:&nbsp;</td>[color=blue]
      > <td align="left" valign="middle" class="smain" width="119"><in put[/color]
      type="text" name="FName" size="15" maxlength="20" tabindex="2"
      ID="Text1"></td>[color=blue]
      > <td align="left" valign="middle" width="1">&nbsp ;</td>
      > <td align="right" valign="middle" class="smain" width="185"><fo nt[/color]
      color="red"><b> *</b></font>&nbsp;Last :&nbsp;</td>[color=blue]
      > <td align="left" valign="middle" class="smain" width="185"><in put[/color]
      type="text" name="LName" size="15" maxlength="20" tabindex="3"
      ID="Text2"></td>[color=blue]
      >
      > <td align="left" valign="middle" class="smain" width="185"><in put[/color]
      type="text" name="Email" size="15" maxlength="20" tabindex="3"
      ID="Text3"></td>[color=blue]
      >
      >
      > </tr>
      >
      > </table>
      >
      >
      > </form>
      >
      >[/color]


      Comment

      Working...