Solved

ASP email form validation

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

19 Experts available now in Live!

Get 1:1 Help Now