1

I have added the client side validations on a form using jQuery's validate() function and assigned rules and it shows the error messages in Red color below the respected fields. I want to show same error messages after performing server side validations done in PHP. Please help.

1
  • 1
    well, then it would have nothing to do with jQuery but PHP, are you using any php frameworks? Commented Dec 22, 2009 at 5:49

4 Answers 4

2

You'll have to perform that logic with PHP, in a sense replicating all that jQuery's validate() plugin does. I generally run through a series of tests, and add errors to an array:

$errors = array();
if (!valid_name($firstname)) $errors[] = "Please provide your first name.";
if (!valid_email($email))    $errors[] = "Please provide a valid email address.";

Then, after all of my rules, I'll decide whether or not to post the data or show the errors:

if (count($errors) > 0) {
  show_errors($errors);
  show_form();
} else {
  submit_data();
}

This is a format that has worked well for me.

Sign up to request clarification or add additional context in comments.

1 Comment

could you please provide an example for the same.
1

You have to just issue a request to the server using jQuery. As far as validation on the server side jQuery has nothing to do with that. jQuery is an advaced javascript framework that runs inside the browser.

Comments

1

There's no automatic way (unless someone built one) that can replicate the client-side validation to server-side.

You might want to see how someone manage to come out with a working solution here:
jQuery for Real time Server-side Form Validation

Comments

0

Is your goal to validate an individual field via a call to your server before you submit the entire form? Essentially you will need to perform a post ($.post) for each piece of data that you want to validate. This link is to the jQuery documentation for Ajax posts.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.