Validate form for email

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Mills

    #1

    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="te xt/html" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <HTML>

    <script>
    function validateform(fo rm)
    {
    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>Quo tation Request Form</H2></CENTER>

    <FORM NAME="QuoteForm " METHOD=POST ACTION="QuoteRe q2.jsp" onSubmit="retur n
    validateform(th is)">

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

    <c:if test="${param.s ubmitted && 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.s ubmitted && 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.s ubmitted && 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>


  • Randy Webb

    #2
    Re: Validate form for email

    Tim Mills wrote:
    [color=blue]
    > 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...
    >[/color]

    <--snip-->
    [color=blue]
    > function validateform(fo rm)
    > {
    > questions = form.elements;
    >
    > if ((questions['toname'].value=="")||
    > (questions['emailto'].value=="")||
    > (questions['quote'].value==""))
    > { alert("Some information is missing from your request.")[/color]


    return false;

    [color=blue]
    > }[/color]

    else{return true}


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

    <--snip-->


    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • RobB

      #3
      Re: Validate form for email

      Tim Mills wrote:[color=blue]
      > The following code asks the user to sumbit a name, email address, and[/color]
      some[color=blue]
      > text for a quotation via a FORM. I have written a javascript function[/color]
      to[color=blue]
      > evaluate the fields in the form and pop-up a message to tell the user[/color]
      if all[color=blue]
      > the fields have been fill-out. If the user has missed some[/color]
      information the[color=blue]
      > form re-displays with red "alerts" indicating where the user have[/color]
      missed the[color=blue]
      > information while re-populating the information the user has[/color]
      submitted.[color=blue]
      >
      > May question is, after the user has successfully filled out the form,[/color]
      how[color=blue]
      > can the submit request be forwarded to another jsp so the information[/color]
      can be[color=blue]
      > emailed to me. I have written a jsp to accept the request and email[/color]
      it. This[color=blue]
      > 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[/color]
      track.[color=blue]
      >
      > Please help...
      >
      > Here is my code .... (file is called QuoteReq2.jsp)
      >
      > <%@ page contentType="te xt/html" %>
      > <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
      > <HTML>
      >
      > <script>
      > function validateform(fo rm)
      > {
      > 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>Quo tation Request Form</H2></CENTER>
      >
      > <FORM NAME="QuoteForm " METHOD=POST ACTION="QuoteRe q2.jsp"[/color]
      onSubmit="retur n[color=blue]
      > validateform(th is)">
      >
      > <input type="hidden" name="submitted " value="true">
      >
      > <c:if test="${param.s ubmitted && 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[/color]
      value="${param. toname}"[color=blue]
      > />">
      > <br>
      > <br>
      >
      > <c:if test="${param.s ubmitted && 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.s ubmitted && 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>[/color]

      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>

      Comment

      Working...