ASP required fileds in E-mail form

M

Mark Creelman

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("send") <> "" Then
Set iConf = CreateObject ("CDO.Configuration")
Set Flds = iConf.Fields


Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = "mail.korax.net"
Flds.Update

Set iMesg = CreateObject("CDO.Message")
Set iMesg.Configuration = iConf

Err.Clear

iMesg.To = "(e-mail address removed)"
iMesg.From = Request.Form("Email")
iMesg.Subject = "Email Form"


str1 = Request.Form("Fname")
str2 = Request.Form("Lname")
str3 = Request.Form("Email")


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


iMesg.Send

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


%>


<body bgcolor="#3E71A8" 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"><font color="red"><b>*</b></font>&nbsp;First:&nbsp;</td>
<td align="left" valign="middle" class="smain" width="119"><input 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"><font color="red"><b>*</b></font>&nbsp;Last:&nbsp;</td>
<td align="left" valign="middle" class="smain" width="185"><input type="text" name="LName" size="15" maxlength="20" tabindex="3" ID="Text2"></td>

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


</tr>

</table>


</form>
 
R

Ray Costanzo [MVP]

The simplest approach is:


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

Ray at home
 
S

Stephanie Stowe

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.asp"> where login.asp is the same page.

Quick hack for demonstration purposes:

<%


dim strMessage, blnError


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

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

end if

%>

<html>
<head>
<title>test</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.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><font color=red>*</font></TD>
</TR>
<TR>
<TD>Name</TD>
<TD><input type=text name=yourname</TD>
</TR>
<TR>
<TD colspan=2><input type=submit value=submit name=submit></TD>

</TR>
</TABLE>


</form>

</body>
</html>


Mark Creelman said:
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("send") <> "" Then
Set iConf = CreateObject ("CDO.Configuration")
Set Flds = iConf.Fields


Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = "mail.korax.net"
Flds.Update

Set iMesg = CreateObject("CDO.Message")
Set iMesg.Configuration = iConf

Err.Clear

iMesg.To = "(e-mail address removed)"
iMesg.From = Request.Form("Email")
iMesg.Subject = "Email Form"


str1 = Request.Form("Fname")
str2 = Request.Form("Lname")
str3 = Request.Form("Email")


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


iMesg.Send

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


%>


<body bgcolor="#3E71A8" 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"><font
color="red"> said:
<td align="left" valign="middle" class="smain" width="119"><input
type="text" name="FName" size="15" maxlength="20" tabindex="2"
ID="Text1"> said:
<td align="left" valign="middle" width="1">&nbsp;</td>
<td align="right" valign="middle" class="smain" width="185"><font
color="red"> said:
<td align="left" valign="middle" class="smain" width="185"><input
type="text" name="LName" size="15" maxlength="20" tabindex="3"
ID="Text2"> said:
<td align="left" valign="middle" class="smain" width="185"><input
type="text" name="Email" size="15" maxlength="20" tabindex="3"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top