471,338 Members | 1,221 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Validate form for email

The following code asks the user to sumbit a name, email address, and some
text for a quotation via a FORM. I have written a javascript function to
evaluate the fields in the form and pop-up a message to tell the user if all
the fields have been fill-out. If the user has missed some information the
form re-displays with red "alerts" indicating where the user have missed the
information while re-populating the information the user has submitted.

May question is, after the user has successfully filled out the form, how
can the submit request be forwarded to another jsp so the information can be
emailed to me. I have written a jsp to accept the request and email it. This
works if I remove the validation code. I am not familiar enough with
javascript to be able to figure this one out. I may be on the wrong track.

Please help...

Here is my code .... (file is called QuoteReq2.jsp)

<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<HTML>

<script>
function validateform(form)
{
questions = form.elements;

if ((questions['toname'].value=="")||
(questions['emailto'].value=="")||
(questions['quote'].value==""))
{ alert("Some information is missing from your request.")
}

}
</script>

<HEADER>
<TITLE>
Quotation Request
</TITLE>
</HEADER>
<BODY>
<CENTER><H2>Quotation Request Form</H2></CENTER>

<FORM NAME="QuoteForm" METHOD=POST ACTION="QuoteReq2.jsp" onSubmit="return
validateform(this)">

<input type="hidden" name="submitted" value="true">

<c:if test="${param.submitted && empty param.toname}">
<font color="red">
Please enter your Name<br>
</font>
</c:if>
Your Name :
<INPUT TYPE=TEXT NAME="toname" Size=4O value="<c:out value="${param.toname}"
/>">
<br>
<br>

<c:if test="${param.submitted && empty param.emailto}">
<font color="red">
You have not entered an E-Mail address.<br>
</font>
</c:if>
E-Mail :
<INPUT TYPE=TEXT NAME="emailto" Size=45 value="<c:out
value="${param.emailto}" />"><br>

<c:if test="${param.submitted && empty param.quote}">
<font color="red">
You have not entered any information for the quotation.<br>
</font>
</c:if>
<br>
<br>
Enter your quotation request :<br>
<TEXTAREA NAME="quote" rows=15 cols=60 wrap=soft>
<c:out value="${param.quote}" />
</TEXTAREA>
<br>
<br>
<INPUT TYPE="image" NAME="submit" src="/buttons/Submit.jpg" border=0
alt="Submit">
</FORM>
</BODY>
</HTML>
Jul 23 '05 #1
2 2242
Tim Mills wrote:
May question is, after the user has successfully filled out the form, how
can the submit request be forwarded to another jsp so the information can be
emailed to me. I have written a jsp to accept the request and email it. This
works if I remove the validation code. I am not familiar enough with
javascript to be able to figure this one out. I may be on the wrong track.

Please help...

<--snip-->
function validateform(form)
{
questions = form.elements;

if ((questions['toname'].value=="")||
(questions['emailto'].value=="")||
(questions['quote'].value==""))
{ alert("Some information is missing from your request.")

return false;

}


else{return true}
Inside the if that stops navigation, return false. Otherwise, return true.

<--snip-->
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Tim Mills wrote:
The following code asks the user to sumbit a name, email address, and some text for a quotation via a FORM. I have written a javascript function to evaluate the fields in the form and pop-up a message to tell the user if all the fields have been fill-out. If the user has missed some information the form re-displays with red "alerts" indicating where the user have missed the information while re-populating the information the user has submitted.
May question is, after the user has successfully filled out the form, how can the submit request be forwarded to another jsp so the information can be emailed to me. I have written a jsp to accept the request and email it. This works if I remove the validation code. I am not familiar enough with
javascript to be able to figure this one out. I may be on the wrong track.
Please help...

Here is my code .... (file is called QuoteReq2.jsp)

<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<HTML>

<script>
function validateform(form)
{
questions = form.elements;

if ((questions['toname'].value=="")||
(questions['emailto'].value=="")||
(questions['quote'].value==""))
{ alert("Some information is missing from your request.")
}

}
</script>

<HEADER>
<TITLE>
Quotation Request
</TITLE>
</HEADER>
<BODY>
<CENTER><H2>Quotation Request Form</H2></CENTER>

<FORM NAME="QuoteForm" METHOD=POST ACTION="QuoteReq2.jsp" onSubmit="return validateform(this)">

<input type="hidden" name="submitted" value="true">

<c:if test="${param.submitted && empty param.toname}">
<font color="red">
Please enter your Name<br>
</font>
</c:if>
Your Name :
<INPUT TYPE=TEXT NAME="toname" Size=4O value="<c:out value="${param.toname}" />">
<br>
<br>

<c:if test="${param.submitted && empty param.emailto}">
<font color="red">
You have not entered an E-Mail address.<br>
</font>
</c:if>
E-Mail :
<INPUT TYPE=TEXT NAME="emailto" Size=45 value="<c:out
value="${param.emailto}" />"><br>

<c:if test="${param.submitted && empty param.quote}">
<font color="red">
You have not entered any information for the quotation.<br>
</font>
</c:if>
<br>
<br>
Enter your quotation request :<br>
<TEXTAREA NAME="quote" rows=15 cols=60 wrap=soft>
<c:out value="${param.quote}" />
</TEXTAREA>
<br>
<br>
<INPUT TYPE="image" NAME="submit" src="/buttons/Submit.jpg" border=0
alt="Submit">
</FORM>
</BODY>
</HTML>


Question: why aren't you doing the entire validation - field checks,
prompting (including those 'red alerts') - and rejecting submission -
at the client? Typically a validator is written to trap as many errors
as possible: JavaScript isn't jsp, but it isn't a toy language either.
Once submission is permitted, always do bullet-proof validation at the
server, naturally.

If you're round-tripping anyway (with errors) there's not much point in
using browser validation...

Interesting tag: <HEADER>

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Techy | last post: by
11 posts views Thread by wolf | last post: by
3 posts views Thread by Martin | last post: by
1 post views Thread by jayparaiso | last post: by
2 posts views Thread by Mick Walker | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.