[eluser]Cgull[/eluser]
Hello,
Does anybody know of a good tutorial to create the login form in a dialog box?
I looked at a few tutorial and I think I made a mess...
What I need:
I have an application where a user should log in if he wants to create or update orders.
After he creates or edit an order, he is automatically being logged out.
I would like to open the login form in a dialog box but I struggle with the validations.
What I have now:
I have a login_view that has this jquery code in it:
Code:
[removed]
jQuery.validator.addMethod("checkPass", function(value, element) {
$.ajax({
type: "POST",
url: "/orders/index.php/verifyLogin/checkDatabaseAjax",
async: false,
data: {password: value},
success: function(data){
$('#passCheck').val(data);
alert(data);
}
});
return $("#passCheck").val() != '0'
}, '<span>The password or username are incorrect.</span>');
$('#loginForm').submit(function(e){
e.preventDefault();
$("#loginForm").validate({
errorElement: "span",
//set the rules for the fild names
rules: {
username: { required: true },
password: { required: true, checkPass: true },
},
//our custom error placement
errorPlacement: function(error, element) { error.appendTo(element.parent()); }
});
});
$("#login").dialog({
position: {
my: 'center',
at: 'center',
collision: 'fit',
of: $('#content')
},
autoOpen: false,
width: 400,
modal: true,
resizable: false,
buttons: {
"Login": function() {
$('#loginForm').submit();
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
[removed]
And I have a verify_login controller with this function it it:
Code:
function checkDatabaseAjax()
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
$password = $this->input->post('password');
//query the database
$result = $this->m_user->login($username, $password);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
'id' => $row->id,
'username' => $row->name
);
$this->session->set_userdata('logged_in', $sess_array);
}
echo "1";
}
else
{
echo "0";
}
}
I have 2 problems:
1. If I don't fill any of the fields, and click the login button nothing happens, if I click it again it shows me the errors of required fields.
2. If I fill in the username and a wrong password, The validation checkPass returns 0 but the error does not display.
Can anyone please help?