By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

Validate form for email

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.