Stop PHP execution after alert

I have a form submit . The user can enter any one field and go ahead. I need to check if at least one field is filled and show appropriate message.On submit js function is executed showing alert that fill at least one field but the php code still executes

Can you post the code here?

Hello,
Assuming you are using php to process to form data and then using php to make javascript alerts popup, all you have to do is use

  1. die("Invalid input");
  2. exit(0);
    Its as easy as that!
    (NOTE: die() is not recommended to handle user errors. Over all it looks horrible). If none of this helped you,
    check out my repo on github and click on the file named register.php, see how i handled users not giveing a username/password with php and then handled the rest with php

Prevent the form’s submission if your condition isn’t met.

function formIsValid(form){
  // do your checks
  // and return true / false accordingly
}

$("form").on("submit", function(e){
  if(!formIsValid(this)){
    alert("Incorrect");
    e.preventDefault();
  }
});

Problem is Solved. I am returning false after condition and also onsubmit="return myfunction()". Thanks for the replies.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.