There is a form

<form method="post" id="orderForm"> <input type=text> <input type=phone> <input type=email id=email> <input type=button id=submit_f> </form> $("#submit_f").click(function() { var email = $('#email').val(); $.ajax({ url: '/ajax/validation/email_validate.php', type: 'post', data: {email: email, type: 'checkEmail'}, success: function(data){ $('form#orderForm').trigger( 'reset' ); if(data == "ok"){ $('#submit_f').prop('disabled', true); $('form#orderForm').submit(); } else { swal("Пользователь с таким email уже существует", "", "error"); } } }) }); 

By clicking on the submit button, there is a check whether the entered email is in the database. And how to add a test for emptiness remaining input . Because I had to change type=submite to type=button required does not work.

  • use $ ("# orderForm"). submit (); - HELO WORD
  • if (input.value.length === 0) // empty input - sivik_xes

1 answer 1

Alternatively, you can add up to $ .ajax ().

But you can (preferably) stuff it into $ .ajax (). BeforeSend ();

 var send = true; $('form#orderForm input[type="text"]').each(function(){ if(!$(this).val() || $(this).val() == ''){ $(this).css('border-color','red');//Сделаем бордер красным send = false; } }); if(!send) return false; //всё что ниже не выполнится пока send будет false