please help
I have a registration form.
I need if someone fill something wrong, the form stop sending data without refreshing or losing data

    I'm not sure what you mean by stop sending data??

    but if you want validate as they enter info you can use an onblur event and call ajax and validate the user input.

      6 days later

      There are three ways to accomplish this.

      1. Use Javascript. Instead of a "submit" button, put a regular button on the form that calls a javascript function that you write. This function should check each field to see that it's complete and in the right format. If all the fields are right, then your function can do a form.submit(); This way, if the form is wrong, the page never refreshes.

      2. A second way is to use Ajax. This is almost exactly like the first solution except that your function uses Ajax to pass the form data to the server to be validated. If the fields are filled out wrong, the server can respond back to the page with an error, the page never refreshes, and the data is still in the fields AND the data exists on the server so that you can follow up with customers who might have had trouble filling out the form which is a huge advantage. Another big advantage is that you can hide your validation requirements from the user if you don't want the general public from knowing them. For example: If you wanted to permit post office boxes on sales over $100 but refuse them on sales less than $100, you could hide that info by doing the validation server side. And a final advantage is that you can have very complex or data intensive validation easily done on the server that you would never want done on the client side. For example: If you wanted to check to see if the CITY matches the ZIP CODE, you wouldn't really want to put 45 megabytes of city and zip code data into a Javascript just to validate someone's form so instead, you pass it to the server for validation there where the zip can be checked against a database or an API or something.

      3. The third way to do this is to allow a refresh of the form and the responding PHP page validates the data and if it's not valid, then it redraws the form with the fields pre-populated with the data. In other words, just because you do a refresh and validate server side doesn't mean the form has to be drawn from scratch with empty values.

        Write a Reply...