Pavlos1316
Pavlos1316

Reputation: 444

jquery and php form validation

I am validating a form using PHP like this (part of it):

if (!($email)){
echo "<br />
<br />
<span class=\"difftext\">Please enter your E-mail!</span>";
exit();
}

Is there a way, by using Jquery, to display the msg without refresh my page or do I have to use totally Jquery validation?

Thank you

EDIT...

('#chkout', 'submit', function(){
   $.ajax({
     type: 'post',
     url: 'help_scripts/prcd_chkout_ondelivery.php',
     data: 'data',
     success: function (){
     $('#cust_order_result').html('data');
     }
 })
 return false;

});

Upvotes: 1

Views: 543

Answers (3)

gmeluski
gmeluski

Reputation: 58

There are two choices: 1) Interrupt the submit process to check for values in your desired input fields using Javascript / JQuery, and allow submission when validation passes.

2) Still use PHP to do the validation, but submit the form using an AJAX call and use the PHP script to set up the cases for successful and unsuccessful validation.

The actual process will vary depending on which one of these two choices you want to use.

Upvotes: 2

Soren
Soren

Reputation: 14688

You can setup an AJAX call using JQuery. The AJAX call will allow you to do the server side verification without doing a page refresh.

Look up change and ajax in the JQuery manual to try to structure cod which will work for your case.

Upvotes: 2

Paul
Paul

Reputation: 141839

You can validate the form before it is submitted using jQuery. Just keep in mind that client-side form validation in no replacement for server-side form validation and you still need to use it too.

Upvotes: 2

Related Questions