Solved

ASP email form validation

Posted on 2007-03-29
4
284 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Group by correlation 4 58
VBScript FormatCurrency - how to change the currency symbol 4 47
SP to delete duplicates 15 70
Index on a Table 6 15
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…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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