How to direct a user directly to a form

后端 未结 1 1934
无人及你
无人及你 2020-12-22 03:19

What I have set up right now is a login form and a signup form that is set into one page, but it toggles back and forth between the forms with some Jquery. When the login fo

相关标签:
1条回答
  • 2020-12-22 03:48

    A common method to solve this problem is to validate the sign-up fields via javascript before the form is submitted.

    You can use javascript/jQuery to interrupt the submit process, check the value of each field, and - if one or more fields fails validation - return false to return control back to the user in order to fix the problems and try again.

    Here are some code examples and demos:

    To interrupt the submit, you just use:

    $('#id_of_your_form').submit(function(){
        let var_valid = true; //any variable name will do...
        //
        //validation code goes here - see next demo below
        //
        if (!var_valid) return false;
        //if the code gets here, it will continue submitting
    });
    

    Here is an example of how to do basic field validation.

    http://jsfiddle.net/W4g4e/7/

    0 讨论(0)
提交回复
热议问题