Jump to content

Stuck with scriptaculous and AJAX


rofl90

Recommended Posts

I'm trying to be like able to login and then it checks it and then it sendsyou either way (Back to login with a appear or slide down with logging in and redirect..)

 

Heres my code:

 

index.js:

 

function dform() {
new Effect.SlideUp('response');
new Effect.Appear('login');
}

function redirect(page) {
window.location = page;
}

function login_to() {
var username = document.login.username.value;
var password = document.login.password.value;
new Effect.SlideUp('login');

var handlerFunc = function(t) {
	if(t.responseText == "login") {
		new Effect.Appear('response2');
		document.getElementById('message2').innerHTML = "<img src=\"images/accept.png\"> <b><u>Logging in!</u></b><br>Please wait a couple of seconds while we finalize the process.<br />";
		setTimeout('redirect(\'main.php\')', 3000);
	}else{
	new Effect.Appear('response');
    	document.getElementById('message').innerHTML = t.responseText;
    	}
}

var errFunc = function(t) {
    	alert('Error ' + t.status + ' -- ' + t.statusText);
}

new Ajax.Request('index.php?action=login', {parameters:'username='+username+'&password='+password+'', onSuccess:handlerFunc, onFailure:errFunc});
}

function checkEnter(e){ //e is event object passed from function invocation
var characterCode;

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
login_to(); //submit the form
return false
}
else{
return true
}

}

 

index.php:

<?php 
session_start ();

include "config.php";
include "classes/settings.php";
include "classes/user.php";
include "classes/core.php";
if($user->check_login() == "1") {
    header("Location: index2.php");
    exit();
}
if($action == "login") {
$username = $_POST["username"];
$password = $_POST["password"];
require_once "classes/login.php";
$login->begin_login($username, $password);
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="description" name="description" content="<?php echo $settings->description();?>" />
<meta http-equiv="keywords" name="keywords" content="<?php echo $settings->keywords(); ?>" />
<title><?php echo $settings->site_title(); ?>» Login:</title>
<link href="<?php echo $url; ?>/backend/css/style.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $url; ?>/backend/js.php" type="text/javascript"/>
<script type="text/javascript" src="javascript/prototype.js"></script>
<script type="text/javascript" src="javascript/scriptaculous.js"></script>
<script type="text/javascript" src="javascript/index.js"></script>
<script type='text/javascript'>
function clearText(findText,text,textID) 
{
if(findText == text) 
{
    	document.getElementById(textID).value = '';
    }
}

function fillText(textID,text)
{
if(document.getElementById(textID).value == '')
{
	document.getElementById(textID).value = text;
}
}
</script>
</head>
<body>
<div id="container">
<div id="top">
	<div id="logo"></div>
</div>
<div id="navbar">
	<div id="navbutton"><a href="<?php echo $url; ?>/backend/">Backend Home</a></div>
	<div id="navbutton"><a href="<?php echo $url; ?>/">View site</a></div>
	<div id="navbutton">
		<!--leave blank-->
	</div>
</div>
<div id="contentcontainer">
	<div id="contentboxcontainer">
		<!-- start side nav -->
		<div id="navboxcontainer">
			<div id="navboxtop"></div>
			<div id="navboxmid">
				<div id="sidenavbutton"><a href="<?php echo $url; ?>/backend/">Backend Home</a></div>
				<div id="sidenavbutton"><a href="<?php echo $url; ?>/">View site</a></div>
			</div>
			<div id="navboxbot"></div>
		</div>
		<div id="contentboxtop"></div>
		<div id="contentboxcontent">
			<div id="title">
				<?php include "welcome.php"; ?>
			</div>
			<?php if(isset($_GET['index_message'])) { echo "<div class=\"error\"> ".$_GET['index_message']. "</div>"; } else {?>
				<div class="warning"> Your IP is <?php echo $_SERVER['REMOTE_ADDR']; ?>, and has been logged, unauthorised attempts to access will be logged, and steps will be taken. Currently the backend timeout is placed at <?php echo floor($settings->timeout() / 60); ?> minutes. (May be rounded)</div><?php } ?>
				<table summary="login">
			<form method="post" name="login">
				<fieldset>
				<legend>Name</legend>
				<input type="text" name="username" value="username..." id="user" onfocus="clearText('username...',this.value,this.id);" onblur="fillText(this.id,'username...');" />
				</fieldset>
				<fieldset>
				<legend>Password</legend>
				<input type="password" name="password" value="password..." id="password" onfocus="clearText('password...',this.value,this.id);" onblur="fillText(this.id,'password...');" onkeypress="checkEnter(event);" />
				</fieldset>
				<fieldset>
				<legend>Login</legend>
				<input type="button" id="submit" name="login" value="Login" onclick="login_to();" />
				</fieldset>
			</form>
			</table>
			<br />
			<br />
			<br />
			<br />
			<br />
			<br />
		</div>
		<div id="contentboxbottom"></div>
	</div>
	<div id="clear"></div>
	<div id="footer"><?php echo $settings->footer(); ?> Powered by <?php echo $settings->get_ver(); ?></div>
</div>
</div>
</body>
</html>

 

What happens when I click login... nothing :( I don't know if anything goes on behin the scenes, but nothing visibly the slide doesn't work...

 

 

Oh also if you'd like it heres login.php:

 

<?php

class login extends database {
private $username;
private $password;
private $ip;
private $level;
private $time;
/**
 * Construct
 */
function __construct() {
	parent::__construct ();

}

public function begin_login($username, $password) {
	$username = mysql_real_escape_string ( $username );
	$password = mysql_real_escape_string ( $password );
	if ($username == "" || $password == "") {
		echo "<b><u>ERROR!</u></b><br>You left a required field blank!<br /><br /><a onclick=\"dform();\" href=\"#\">Try Again?</a>";
		exit ();
	} else {
		$password = md5 ( $password );
		$this->username = $username;
		$this->password = $password;
		$this->ip = $_SERVER ["REMOTE_ADDR"];
		$this->time = time ();
		$this->check_username ();
	}
}

public function check_username() {
	$get_user = $this->query ( "SELECT username FROM users WHERE username='$this->username'" );
	$get_user_n = $this->num_rows ( $get_user );
	if ($get_user_n == "0") {
		$data = "Username: $this->username \n";
		$data .= "Password: $this->password \n";
		$data .= "Time: $this->time \n";
		$data .= "IP: $this->ip \n";
		$data .= "Type: BAD USERNAME";
		$this->query ( "INSERT INTO logins (data) VALUES('$data')" );
		echo "<b><u>ERROR!</u></b><br>Incorrect username!<br /><br /><a onclick=\"dform();\" href=\"#\">Try Again?</a>";
		exit ();
	} else {
		$this->check_password ();
	}
}

public function check_password() {
	$get_user_p = $this->query ( "SELECT username, password FROM users WHERE username='$this->username' AND password='$this->password'" );
	$get_user_p_n = $this->num_rows ( $get_user_p );
	if ($get_user_p_n == "0") {
		$data = "Username: $this->username \n";
		$data .= "Password: $this->password \n";
		$data .= "Time: $this->time \n";
		$data .= "IP: $this->ip \n";
		$data .= "Type: BAD PASSWORD";
		$this->query ( "INSERT INTO logins (data) VALUES('$data')" );
		echo " <b><u>ERROR!</u></b><br>Incorrect password for this username!<br /><br /><a onclick=\"dform();\" href=\"#\">Try Again?</a>";
		exit ();
	} else {
		$this->check_banned ();
	}
}

public function check_banned() {
	$get_user_b = $this->query ( "SELECT banned FROM users WHERE username='$this->username'" );
	$get_user_b_a = $this->fetch_array ( $get_user_b );
	if ($get_user_b_a ["banned"] == "1") {
		echo " <b><u>ERROR!</u></b><br>This account is banned!<br /><br /><a onclick=\"dform();\" href=\"#\">Try Again?</a>";
		exit ();
	} else {
		$this->set_session();
	}
}

public function set_session() {
	$myuid_query = $this->query("SELECT id FROM users WHERE username='$this->username'");
	$myuid_arr = $this->fetch_array($myuid_query);
	$uid = $myuid_arr['id'];
	$this->time = time();
	$this->query("DELETE FROM sessions WHERE uid='$uid'");
	$this->query("INSERT INTO sessions (session_id, time, ip, uid) VALUES('$myuid', '$this->time', '$this->ip', '$uid')");
	echo "login";
}

/**
 * Destruct
 */
function __destruct() {

}
}

if (! isset ( $login )) {
$login = new login ( );
}

?>

Link to comment
https://forums.phpfreaks.com/topic/99044-stuck-with-scriptaculous-and-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.