Check $_POST data with jquery before submitting the form

后端 未结 3 1322
面向向阳花
面向向阳花 2021-01-23 21:37

I have a form that sends the store the First Name of the user in a database. I was checking the information send by the user using regex in php. To mak

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-23 22:18

    Firstly you should ALWAYS validate server side for form submission, especially if you are passing those value along to a DB - SQL injection, the struggle is real.

    As for the form submission flow you can...

    return true
    

    ... after the valid name alert and the form to submit as it normally would.

    Since you already have bound to that submit event, It would be even better for the user if you submitted the form via ajax, and providing feedback if the server validation fails. Thus the user never leaves the page and you are able to handle both client and server validation.

    Take a look at ParsleyJS - http://parsleyjs.org/ - w00t!

提交回复
热议问题