#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Exclamation How to make JQueryUI dialog login form?


    loginSend.js
    Code:
    $('#loginButton').on('click', function(){ //the id of the submit button = #loginButton
    	
    	var username = $('#userfield').val();
    	var password = $('#passfield').val();
    	
    	if (username.length == 0 || password.length == 0 || password.length < 6) { // checks if username and pass have been entered
    	
    		$('#fillFields').text('*Please enter a valid username/password'); //#fillfields = the div where error message should appear in JQuery UI dialog box
    	} else {
    		
    		//$('#formLogin').text('You have successfully logged in').dialog('close'); //Closes dialog box if logged in currently not in use
    		$.post('loginProcess.php', {username: username, password: password}, funtion(data){ // sends data to loginProcess.php
    		
    			if (data == true){ //checks if the loginProcess has returned true (if the username exists or not)
    				alert('true'); // just to check if the code works, display an alert message
    			}
    	}
    		
    	});
    });
    loginProcess.php
    Code:
    <?php
    
    require 'config.php';
    
    //  LOGIN FORM Process
    
    if (user_exists('super')){ //user_exists() = a user defined function in config.php
    	return true;
    }
    ?>
    <?php
    config.php
    Code:
    function sanitize($data){
    	return mysql_real_escape_string(strip_tags($data));
    }
    
    function user_exists($username){
    
    	$username = sanitize($username);
    	$query = mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `Username` = '$username'");
    	return (mysql_result($query, 0) == 1) ? true : false;
    }
    ?>
    i don't understand what I've done wrong. I'm trying to create a JQuery UI dialog, login form. Normlly when the user types in a username i want it to check if the username exists. But nothing happens. Since i added JQuery Post it doesn't work. How do i get it to display if username exists or not. I think the problem is in $.post because before i added that, my code works, but after i added it it stopped working. It doesn't even display error messages? The whole code just doesn't work.

    How do i fix this and get it to work as intended?

    Thanks
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!

IMN logo majestic logo threadwatch logo seochat tools logo