Solved

ASP email form validation

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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