0

I have a form that registers and logs in at the same time but will only allow registration by specific domain, what I need it to do is highlight and not console.log and more importantly prevent the form submitting if not valid.

PHP Form

<form action="actions/register-action.php" method="POST">

    <input class="domain-first" type="text" name="email" placeholder="Email" autocomplete="off" required >

    <input type="password" name="password" placeholder="Password" required>

    <input type="submit" name="submit" value="Register & Login" class="submit-form">

</form>

JQuery

$('.submit-form').on('click', function(){
    str = $('.domain-first').val();
    str = str.split('@').slice(1);

    var allowedDomains = [ 'domain1.co.uk', 'domain2.co.uk' ];

    if ($.inArray(str[0], allowedDomains) !== -1) {
        alert(str + ' is allowed');
    }else{
        alert('not allowed');
    }
}); 
YVS1102
  • 2,658
  • 5
  • 34
  • 63
danjbh
  • 615
  • 10
  • 21
  • relation to php is what here? there's no code for it which suggests you either thought that it is irrelevant or you want your jQuery method be converted to php (by us). – Funk Forty Niner Dec 22 '16 at 14:47
  • Possible duplicate of [Using JQuery - preventing form from submitting](http://stackoverflow.com/questions/9347282/using-jquery-preventing-form-from-submitting) – Mike Scotty Dec 22 '16 at 14:48
  • @Fred-ii- Essentially I just need to prevent the form submitting IF the failure occurs during the validations on the form in the JQuery – danjbh Dec 22 '16 at 14:49
  • if you're looking for a jQuery method, then @mpf82 posted a possible duplicate. If you're looking for a "Plan B" method being a serverside method, then you need to check if any of the inputs are not empty/valid and execute accordingly. – Funk Forty Niner Dec 22 '16 at 14:52
  • 1
    Just add `else{ return false }` – Moses Schwartz Dec 22 '16 at 14:58

1 Answers1

1

You can just add else{return false}

Moses Schwartz
  • 2,857
  • 1
  • 20
  • 32