Solved

ASP email form validation

Posted on 2007-03-29
4
283 Views
Last Modified: 2012-08-13
I have an ASP contact form that works, it emails through the info submitted. I now need it to validate.

here is the form:

<form method=Post action=get.asp>
  <table width="386" border="0" align="center">
    <tr>
      <td width="158">Name</td>
      <td width="218"><input type="text" name="t1" size="30"></td>
    </tr>
    <tr>
      <td>Company</td>
      <td><input type="text" name="t2" size="30"></td>
    </tr>
    <tr>
      <td>Phone</td>
      <td><input type="text" name="t3" size="30"></td>
    </tr>
    <tr>
      <td>Email</td>
      <td><input type="text" name="t4" size="30"></td>
    </tr>
    <tr>
      <td><p>Country</p>        </td>
      <td><input type="text" name="t5" size="30"></td>
    </tr>
    <tr>
      <td valign="top">Enquiry</td>
      <td><textarea name="t6" cols="35" rows="6"></textarea></td>
    </tr>
  </table>
  <p align="center">
    <input type=submit value=Submit>
  </p>
  </form>



and here is the get.asp file:

<%
Dim t1name,t1,t2name,t2,t3name,t3,t4name,t4,t5name,t5,t6name,t6
t1name = "Name"
t1 = Request.Form("t1")
t2name = "Company"
t2 = Request.Form("t2")
t3name = "Phone"
t3 = Request.Form("t3")
t4name = "Email"
t4 = Request.Form("t4")
t5name = "Country"
t5 = Request.Form("t5")
t6name = "Enquiry"
t6 = Request.Form("t6")

Set JMail = Server.CreateObject("JMail.SMTPMail")
JMail.ServerAddress = "mail.site.com:25"
JMail.AddRecipient "sales@address.com"
JMail.Sender = "sales@address.com"
JMail.Subject = "Form Submission"
JMail.Body = t1name & vbcrlf&_
t1 & vbcrlf&_
t2name & vbcrlf&_
t2 & vbcrlf&_
t3name & vbcrlf&_
t3 & vbcrlf&_
t4name & vbcrlf&_
t4 & vbcrlf&_
t5name & vbcrlf&_
t5 & vbcrlf&_
t6name & vbcrlf&_
t6
JMail.Execute

Response.Redirect "http://www.site.com.au/default.asp"

%>

(I have changed the email addresses and web addresses as they are clients)
0
Comment
Question by:aarondarr
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 18814350
Hello aarondarr,

where do you want to validate at server or at client?

Regards,

ivostoykov
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 18814736
Hello

Best way is to add client side validators.. ie in Javascript..
==============================================
<SCRIPT LANGUAGE="JAVASCRIPT">
function formValidate(frm)
{
   if(frm.t1.value != "")
   {
      alert("Please enter a value for name.")
      frm.t1.focus();
      return false;
   }
}
</SCRIPT>
<form method=Post action=get.asp onSubmit="return formValidate()">

=============================================================

Above code will give u a basic idea how it need to be implemented..

Regards
Neeraj
0
 

Author Comment

by:aarondarr
ID: 18814893
I will take a look at that in the morning Neeraj, I also have seen on some forms in an email address field you must add " @", I want to incorporate this into the validation too.
0
 
LVL 22

Accepted Solution

by:
neeraj523 earned 500 total points
ID: 18814975
Hello

Here is the complete solution.. This will check if user has eneterd atleast some value for each fields and email id is valid ie having @

===========================================================
<SCRIPT LANGUAGE="JAVASCRIPT">
function formValidate(frm)
{
      if(frm.t1.value == "")
         {
      alert("Please enter a value for name.")
      frm.t1.focus();
      return false;
   }
      else if(frm.t2.value == "")
         {
      alert("Please enter a value.")
      frm.t2.focus();
      return false;
   }
      else if(frm.t3.value == "")
         {
      alert("Please enter a value.")
      frm.t3.focus();
      return false;
   }
      else if(frm.t4.value == "")
         {
      alert("Please enter a value.")
      frm.t4.focus();
      return false;
   }
         else if(frm.t4.value.indexOf("@") == -1)
         {
      alert("Please enter a valid email id.")
      frm.t4.focus();
      return false;
   }

      else if(frm.t5.value == "")
         {
      alert("Please enter a value.")
      frm.t5.focus();
      return false;
   }
      else if(frm.t6.value == "")
         {
      alert("Please enter a value.")
      frm.t6.focus();
      return false;
   }
}
</SCRIPT>
<form method=Post action=get.asp onSubmit="return formValidate(this)">
  <table width="386" border="0" align="center">
    <tr>
      <td width="158">Name</td>
      <td width="218"><input type="text" name="t1" size="30"></td>
    </tr>
    <tr>
      <td>Company</td>
      <td><input type="text" name="t2" size="30"></td>
    </tr>
    <tr>
      <td>Phone</td>
      <td><input type="text" name="t3" size="30"></td>
    </tr>
    <tr>
      <td>Email</td>
      <td><input type="text" name="t4" size="30"></td>
    </tr>
    <tr>
      <td><p>Country</p>        </td>
      <td><input type="text" name="t5" size="30"></td>
    </tr>
    <tr>
      <td valign="top">Enquiry</td>
      <td><textarea name="t6" cols="35" rows="6"></textarea></td>
    </tr>
  </table>
  <p align="center">
    <input type=submit value=Submit>
  </p>
  </form>
=================================================================

neeraj523
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JQuery Date Time picker not showing 29 109
Dreamweaver server behavior gone 6 108
Live mode in DW, need to creae Session 4 76
Need to rewrite code for checking if a file exists 3 57
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now