CodeIgniter Forums
Need form submit help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Need form submit help (/showthread.php?tid=18503)



Need form submit help - El Forum - 05-08-2009

[eluser]nandish[/eluser]
trying to validate before form submit, its validating and giving alert message ,its not stoping form submit at all

Thanks

Code:
function validateLogin() {
if (!Checkvaliduser())
{
    return false;
}
}

//--------------------------------------------------------
function Checkvaliduser(){
    var userID = $("#userid").val();
    var passwordvalue = $("#password").val();
   if($.trim(userID)!= "" && $.trim(passwordvalue)!= ""){
                var checkUser=true;

       $.get("/index.php/clogon/verifyLogin/" + userID + "/" + passwordvalue,function(data) {
                   if(data.toString() == "0") {
                       checkUser = false;
                }
       });

            if(!checkUser) {  
                 alert("Invalid User ID and Password");
                      $("#userid").focus();
                       return false;
            }
return checkUser;
}
}

Edited by Michael Wales: Removed the coloring, added code tags.


Need form submit help - El Forum - 05-08-2009

[eluser]Evil Wizard[/eluser]
I assume that is JavaScript?

Using something like jquery to overwrite and hook into the form submit event
Code:
$(document).ready(function () {
    $('#form_id').submit( function () {
                 if(validateLogin()) {
                        $('#form_id').submit();
                 };
                 return false;
        });
forcing the submit to return false all the time prevents the form from being submitted except by execution of code.