Search code examples
jqueryjquery-validation-engine

jquery ajax validation engine not working


my jquery validation form is not validate ..here is the code like

    <script type='text/javascript'>
    $(document).ready(function()
    {

    $('#frm').validationEngine('validate');
    });
</script>

<div id='gap'> </div>
    <div id='main'>
        <div id='login-box'>
            <h2><span> ".HD_LOGIN." </span></h2>
            <table align='center'>
            <form id='frm' name='frm' >
                <tr> 
                    <td class='name'> <span>".LBL_USERNAME." </span> </td>
                    <td> <span> &nbsp; </span> </td>
                    <td> <input type='text' name='username' id='username' class='input validate[required]'/><input type='hidden' name='login' value='1' /></td>
                </tr>
                <tr>
                    <td id='error-show'> <span> &nbsp </span> </td> 
                </tr>
                <tr> 
                    <td class='name'> <span>".LBL_PASSWORD."</span></td>
                    <td> <span> &nbsp; </span> </td>
                    <td> <input  type='password' name='password' id='password' class='input validate[required]'/></td> 
                </tr>
                <tr>
                    <td id='error-show'><span> &nbsp; </span> </td> 
                </tr>
                <tr>
                    <td> <span> &nbsp; </span> </td>
                    <td> <span> &nbsp; </span> </td>
                    <td> <input class='chckbx' type='checkbox' name='rememberme' value='1'/> <span> ".CHCK_LOGGED." </span> </td> 
                </tr>
                <tr>
                    <td> <span> &nbsp </span> </td> 
                </tr>
                <tr> 
                    <td colspan='3' align='center'> <input type='button' name='but'  value='login' onclick=\"general_ajax1('modules/login/logincontroller.php',$('#frm').serialize())\"/></td> 
                </tr>

            </form> 

now below is custom ajax

if($("#frm").validationEngine('validate'))
       {
function general_ajax1(urld,data)
{
   $.ajax({
        type:'POST',
        url:urld,
        data:data,
        success: function(response){$('#main_content').html(response);}
        });
    }
}

Solution

  • The error is in your HTML. You've put a 'form' tag inside a 'table' tag and this is not allowed.

    <table align='center'>
         <form id='frm' name='frm' > <---- no!
             <tr> 
    

    You have to do this:

    <form id='frm' name='frm' > <---- no!
        <table align='center'>
            <tr> 
    

    Remember to put the '/form' tag outside the '/table' tag in the end of file.

    Also, the plugin seems to have a bug (I'm using the the master version on github). The 'validateAttribute' is undefined by default. Configure it on dom ready event.

    $(function(){
       $.validationEngine.defaults.validateAttribute = "class";
    });
    

    This will put the things in order...