I am using xajax with my php form which saves data to mysql table.
Now i have it like this:

input where user gives his name,
dropdown1 where user picks a car manufacturers,
dropdown2 is inside of a div where xajax function is used to create and fill the dropdown2 with car models,
submit button

When user clicks the submit button i also have some javascript to validate the form and in my function where posted values are saved in database i also check the values with php.

Would it be better that when user clicks the submit button i have a xajax function that validate the form and then saves the data to mysql table?

Any advice how ajax is used in php foms correctly?

    Using javascript to validate the form is good for two purposes: it gives instant feedback to the user and it saves your server one request.
    But you should always validate data server side as well, since there is no guarantee that you get validated data. Anyone can forge their own request with whatever data they like.

      thx for reply. I am doing now basicly what you suggested. I have a validation in javascript and also with php on server side. What i wanna now is what is the common way to make forms using ajax and would it be better to make my form some otherway like also having a ajax function to handle the submitted data cause if user turns javascript off the form dosent save anythink to database when i have a ajax function which validates the submitted form values and if validation is ok then saves the values in to a database.

        The standard method would be to use a submit button to send the form in the normal way, but use the form's onsubmit event to validate and cancel the submit if necessary. If javascript is turned off the submit will still happen, but the validation occurs on the server.

        So AJAX isn't actually necessary here but you may have other reasons, of course.

        Here's a decent intro http://www.quirksmode.org/js/forms.html.

        P.

          thx for reply. Those articles were kinda old but i hadent thought about onsubmit event. Even with ajax is it possible to make validation server side it really aint that smart cause people that dont have javascript enabled cannot send form. In my case i have a form that only works with javascript on cause of those dropboxes so can anyone give a link to a example that has form with validation server side using ajax? possible using some js framework :rolleyes:

            You don't use a client-side language like JavaScript (as ajax or anything else) to do server-side validation. You use a server-side language like PHP.

              Write a Reply...