Solved

ASP email form validation

Posted on 2007-03-29
4
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

615 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