0

I have got this form , actually working with newsletter mailer v1.3, I would like to validate email address on this form showing the alert in the same page as the form rather than going to a no designed white html error page where the newsletter mailer is showing the error.

Is that possible?I need help, I know I am not a programmer but believe me I am learning thousands of different things on this website :)

`

<section id="newsletter">
    <div class="overlay"></div> <!-- overlay layer -->
    <!-- container -->
    <div class="container">
        <h3 class="heading-l">SUBSCRIBE TO MY NEWSLETTER</h3>
        <!-- subscribe form -->

        <form id="FormViewForm" method="post" action="/NewsletterMailer/subscribe/4" accept-charset="utf-8">
            <input type="hidden" name="_method" value="POST" />
            <input type="hidden" name="data[Form][id]" value="4" id="FormId" />
            <input type="hidden" name="data[Form][type]" value="1" id="FormType" />
            <input type="email" name="data[Form][e-mail]" value="" id="subscribe-email" placeholder="Enter your email..." required>
                <input type="submit" value="+" class="large" id="subscribe-submit" onclick="emailValidator1(document.getElementById('emailer'), 'Not a Valid Email')"
                    value='Check Field'>                        </form>
        <!-- /subscribe form -->
    </div>
    <!-- /container -->


</section>`

and I have this alert

<p class="error">Error - Please Enter A Valid Email Address</p>

I know about the validate stuff but I do not really how to implement it, I tried some examples from the web but unsuccessfully.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
theitboy
  • 1
  • 1
  • possible duplicate of [Validate email address in JavaScript?](http://stackoverflow.com/questions/46155/validate-email-address-in-javascript) – jfriend00 Jan 17 '14 at 17:07

1 Answers1

0

Place this in your HTML after the form.

<script src="http://www.codelib.net/home/jkm/val.js"></script>
<script>
email_verify_settings = {
    'data[Form][e-mail]': { verify: email, filter: 1 }
};
document.getElementById('FormViewForm').onsubmit = function() {
    return validate(this, email_verify_settings);
}
</script>

Are you sure that your form field's name is "data[Form][e-mail]" on the client side? That sounds a little bit weird, but if that's the correct name of the email input field, then the above script should work. Also, you should make a local copy of the validation script from codelib.net and put it on your own server.

Joseph Myers
  • 6,434
  • 27
  • 36