Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

NöU@

Ocultar Div com JavaScript e PHP

Recommended Posts

E aí pessoal.. beleza?

 

To com um probleminha aki..

Eu tenho um sistema de login php aki e o seguinte:

-->caso exita o usuário, ele vai pra página x.php

-->senão, na mesma página do login, aparece um div dizendo q não existe o usuário.

 

o problema eh q eu não to conseguindo a div aparece e desaparece depois de um teste em php:

segue o código;

 

<?php require_once('../Connections/Conexao.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

}

?>

<?php

// *** Validate request to login to this site.

if (!isset($_SESSION)) {

session_start();

}

 

$loginFormAction = $_SERVER['PHP_SELF'];

if (isset($_GET['accesscheck'])) {

$_SESSION['PrevUrl'] = $_GET['accesscheck'];

}

 

if (isset($_POST['login'])) {

$loginUsername=$_POST['login'];

$password=$_POST['senha'];

$MM_fldUserAuthorization = "";

$MM_redirectLoginSuccess = "/escolacleia/etc/principal.php";

$MM_redirectLoginFailed = "/escolacleia/etc/index.php";

$MM_redirecttoReferrer = false;

mysql_select_db($database_Conexao, $Conexao);

 

$LoginRS__query=sprintf("SELECT login, senha FROM `admin` WHERE login=%s AND senha=%s",

GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

 

$LoginRS = mysql_query($LoginRS__query, $Conexao) or die(mysql_error());

$loginFoundUser = mysql_num_rows($LoginRS);

if ($loginFoundUser) {

$loginStrGroup = "";

 

//declare two session variables and assign them

$_SESSION['MM_Username'] = $loginUsername;

$_SESSION['MM_UserGroup'] = $loginStrGroup;

 

if (isset($_SESSION['PrevUrl']) && false) {

$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];

}

header("Location: " . $MM_redirectLoginSuccess );

echo "<script type=\"text/Javascript\">camada(erro, false)</script>"; chamada da função no teste php

}

else {

header("Location: ". $MM_redirectLoginFailed );

echo "<script type=\"text/Javascript\">camada(erro, true)</script>"; chamada da função no teste php

}

}

?>

<!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=utf-8" />

<title>Untitled Document</title>

<link href="/escolacleia/scripts/CSS/restrito.css" rel="stylesheet" type="text/css" />

<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>

<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

<div id="titulo"><strong>Área Restrita - LOGIN</strong></div><br />

<div id="erro">Login/Senha Inválidos. Por favor, informe corretamente as informações.</div>div q aparece se dá erro

<form id="frmlogin" name="frmlogin" method="POST" action="<?php echo $loginFormAction; ?>" enctype="application/x-www-form-urlencoded">

<span id="edtLogin">

<label>Login:

<input type="text" name="login" id="login" />

</label>

<span class="textfieldRequiredMsg">O campo não pode ser vazio.</span><span class="textfieldInvalidFormatMsg">Formato Inválido.</span></span><br /><br />

<span id="edtSenha">

<label>Senha:

<input type="password" name="senha" id="senha" />

</label>

<span class="textfieldRequiredMsg">O campo não pode ser vazio.</span><span class="textfieldInvalidFormatMsg">Formato Inválido.</span></span><br /><br />

<input name="enviar" type="submit" value="Login" />

<input type="reset" name="Reset" id="button" value="Limpar" />

</form>

<script type="text/javascript">

<!--

var sprytextfield1 = new Spry.Widget.ValidationTextField("edtLogin", "custom", {validateOn:["blur"]});

var sprytextfield3 = new Spry.Widget.ValidationTextField("edtSenha", "custom", {validateOn:["blur"]});

//-->

function camada( sId, visivel ) { //função que esconde/mostra a camada

var sDiv = document.getElementById( sId );

if( visivel == "true" ) {

sDiv.style.visibility = "visible";

} else {

sDiv.style.visibility = "hidden";

}

}

</script>

</body>

</html>

o código de esconder/mostrar a div não funciona...

 

Qualquer ajuda eh vinda...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tenta assim:

 

 

function camada( sId, visivel ) { //função que esconde/mostra a camada
var sDiv = document.getElementById( sId );
if( visivel == true ) {
sDiv.style.visibility = "visible";
} else {
sDiv.style.visibility = "hidden";
}
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Vlw pela ajuda..

 

mas não funcionou =/....

pode ser q eu esteja chamado a função no lugar errado...

 

se puderem me ajuda...

 

Vlw desde já

Compartilhar este post


Link para o post
Compartilhar em outros sites

Esse código aee é bem antigo hein rsss

não se utiliza mais visibilidade assim e tem coisas no php que da pra fazer de um modo mais simples, mas alterei poucas coisas para naum mudar mt a sua lógica

 

tente assim, dei uma alterada no código e deixei alguns comentários.

 

 

<?php require_once('../Connections/Conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['login'])) {
$loginUsername=$_POST['login'];
$password=$_POST['senha'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/escolacleia/etc/principal.php";
$MM_redirectLoginFailed = "/escolacleia/etc/index.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Conexao, $Conexao);

$LoginRS__query=sprintf("SELECT login, senha FROM `admin` WHERE login=%s AND senha=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

$LoginRS = mysql_query($LoginRS__query, $Conexao) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";


//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
//substitui esse codigo aqui;
$displayErro = false;
}
else {
header("Location: ". $MM_redirectLoginFailed );
//substitui esse codigo aqui;
$displayErro = true;
}
}


?>
<!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=utf-8" />
<title>Untitled Document</title>
<link href="/escolacleia/scripts/CSS/restrito.css" rel="stylesheet" type="text/css" />
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />

</head>

<!-- mexi aqui tb -->
<body onload="java script:camada('erro','<?=$displayErro?>') ">
<!--			  -->

<div id="titulo"><strong>Área Restrita - LOGIN</strong></div><br />
<div id="erro">Login/Senha Inválidos. Por favor, informe corretamente as informações.</div>div q aparece se dá erro
<form id="frmlogin" name="frmlogin" method="POST" action="<?php echo $loginFormAction; ?>" enctype="application/x-www-form-urlencoded">
<span id="edtLogin">
<label>Login:
<input type="text" name="login" id="login" />
</label>
<span class="textfieldRequiredMsg">O campo não pode ser vazio.</span><span class="textfieldInvalidFormatMsg">Formato Inválido.</span></span><br /><br />
<span id="edtSenha">
<label>Senha:
<input type="password" name="senha" id="senha" />
</label>
<span class="textfieldRequiredMsg">O campo não pode ser vazio.</span><span class="textfieldInvalidFormatMsg">Formato Inválido.</span></span><br /><br />
<input name="enviar" type="submit" value="Login" />
<input type="reset" name="Reset" id="button" value="Limpar" />
</form>

<!-- alterei o javascript -->
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("edtLogin", "custom", {validateOn:["blur"]});
var sprytextfield3 = new Spry.Widget.ValidationTextField("edtSenha", "custom", {validateOn:["blur"]});
//-->
function camada( sId, visivel ) { //função que esconde/mostra a camada
var sDiv = document.getElementById( sId );
if( visivel == "true" ) {
sDiv.style.display = "block";
} else {
sDiv.style.display = "none";
}
}
</script>
</body>
</html>

 

espero q funfe, pois naum tive como testar.

 

abss

Compartilhar este post


Link para o post
Compartilhar em outros sites

Aee...

 

Funcionou!! http://forum.imasters.com.br/public/style_emoticons/default/clap.gif http://forum.imasters.com.br/public/style_emoticons/default/clap.gif http://forum.imasters.com.br/public/style_emoticons/default/clap.gif

 

Mas uma coisa...

Quando a página é carregada na primeira vez, já aparece a DIV...

 

Se puderem ajudar..

 

Mas vlw.. Funcionou...

Compartilhar este post


Link para o post
Compartilhar em outros sites

é só você colocar la na div o parâmetro style assim:

 

<div style="display:none">

 

absss

Compartilhar este post


Link para o post
Compartilhar em outros sites

rsrs

mas não era pra esconder rs?

 

Seguinte o ( style="display:block" ) a div aparece e ( style="display:none" a div some)

 

Aee no javascript eu altero isso para a div aparecer e sumir e aparecer de acordo com o q precisa.

No caso é só ver quando você quer q ela aparece e altere esse parâmetro saca?

 

Absss rapaz.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.