1

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;

});

3 Answers 3

2

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.

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

Comments

2

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.

4 Comments

So I have to validate by using Jquery... I wished to find a way for it :) Never mind. Thank you
What I was saying is that you should keep you PHP form validation, even after you add jQuery form validation. It's important to have some sort of validation on your server.
@Pavlos1316 We need to see the form field you are trying to validate before we can tell you how to validate it in jQuery
Yes I understood that... And I will... My problem is the msg display thus I will have to use Jquery.
2

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.

2 Comments

Would something like the above edit work??? Is it something like that I need? (your 2nd way?)
that looks like it will work, for sure. EDIT: apologies for the delayed reply!

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.