hello boss! can any one help me to do this. :S

my .ajaxForm() code is working but i want to have validation first for the field before ajax start to work.

here's my code:
my script:

    <script> 
        $(document).ready(function() 
            { 

            $('#myForm').validate({ 
                        rules: {
                            newsletter: {
                                required: true,
                                email: true}
                        }
            });

            $('#myForm').ajaxForm(function() {
                alert("Thank you!"); 
            }); 

        }); 
    </script> 

my form:

     <form id="myForm" action="savenewsletter.php" method="post"> 
        Name: <input type="text" name="newsletter" /> 
        <input type="submit" value="Submit Comment" /> 
     </form>

my php

mysql_query("INSERT INTO newsletter_tb (newsLetterEmail) VALUES ('$_POST[newsletter]')");
Member Avatar for diafol

You seem to be leaving out some functions. What plugins are you using?

Hi, this looks like jquery.form.js and the jquery validation plugin. This could be because the ajaxForm method is getting executed first. Does re-ordering your links to the plugins help? so you have your jquery library first, then your validation plugin and then your jquery.form.js?

If you're using the ajaxForm plugin that I think you're using (http://malsup.com/jquery/form/) this has built in validation already. But if you want to use this other validation, you can do use the 'beforeSubmit' callback and then call the other validation plugin. That is if you are indeed using the mentioned plugin.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.