$_SESSION HIDE Values Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

$_SESSION HIDE Values Problem

Post by maddenuk »

I'm using some AJAX based validation along with PHP $_SESSION to hide the error message until it needs to be displayed. Problem is that when you first come onto the page the error messages for the passwords are still displayed. I've tried everything and have checked to see if there are any errors in the syntax or naming of the id but can't locate the problem. Any advice?

Cheers

http://www.creativebubbles.co.uk/demo1/resets/reset.php

Code: Select all

<?php 
session_start(); 

if (!isset($_SESSION['values'])) 
{ 
    $_SESSION['values']['txtEmail'] = ''; 
    $_SESSION['values']['txtEmailChecker'] = ''; 
    $_SESSION['values']['txtUsername'] = ''; 
    $_SESSION['values']['txtOldPassword'] = ''; 
    $_SESSION['values']['txtNewPassword'] = ''; 
    $_SESSION['values']['txtNewPasswordChecker'] = ''; 
} 

if (!isset($_SESSION['errors'])) 
{ 

    $_SESSION['errors']['txtEmail'] = 'hidden'; 
    $_SESSION['errors']['txtEmailChecker'] = 'hidden'; 
    $_SESSION['errors']['txtUsername'] = 'hidden'; 
    $_SESSION['errors']['txtOldPassword'] = 'hidden'; 
    $_SESSION['errors']['txtNewPassword'] = 'hidden'; 
    $_SESSION['errors']['txtNewPasswordChecker'] = 'hidden'; 

} 


?>

Code: Select all

<?php require_once('../scripts/validate_header_reset.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"><!-- InstanceBegin template="/Templates/template-1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Investor Eye</title>
<link href="../style/validate.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../scripts/validate_reset.js"></script>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="../style/investor.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#Layer1 {
	position:relative;
	width:200px;
	height:115px;
	z-index:3;
	float: left;
}
#Layer2 {
	position:relative;
	width:200px;
	height:115px;
	z-index:1;
	float: left;
}
-->
</style>
</head>


<body onload="setFocus()"><div id="main_wrapper">
<div id="wrapper">
  <div id="nav"><img src="../images/nav.jpg" width="485" height="20" border="0" usemap="#Map" />
<map name="Map" id="Map"><area shape="rect" coords="7,3,45,18" href="#" /><area shape="rect" coords="54,3,122,18" href="#" /><area shape="rect" coords="130,4,186,17" href="#" /><area shape="rect" coords="195,3,239,17" href="#" /><area shape="rect" coords="248,3,301,17" href="#" /></map><img src="../images/p_tr.jpg" width="6" height="6" class="tr_link" /><img src="../images/p_tl.jpg" width="6" height="6" class="tl_link" /></div>
  <div id="top">
    <div id="flash"></div>
    <div id="logo_area">
      <div id="logo"><img src="../images/logo.jpg" width="199" height="56" /></div>
	  
      <div id="txt_area"><img src="../images/g_bl.jpg" class="bl_link" /><img src="../images/g_br.jpg" width="6" height="6" class="br_link" /><img src="../images/g_tl.jpg" width="6" height="6" class="tl_link" /><img src="../images/g_tr.jpg" width="6" height="6" class="tr_link" /></div>
    </div>
  </div>
  
  <div id="middle"><!-- InstanceBeginEditable name="EditRegion3" -->
    <div id="txt_area1">
	  <h1>Reset your  password </h1>
	  <p>Enter your details in the form below to reset your password. On submission you will receive an email confirming your new password. <br />
          <br />
	    If you have forgotten your username please click here </p>
	    <form name="frmReset" action="./../scripts/validate_reset.php?validationType=reset" method="post" enctype="multipart/form-data">
      <div id="form_tbl_1">
	      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="form_txt">
             <tr>
            <td width="46%"><label for="txtUsername">Username</label></td>
            <td width="54%"><input type="text" name="txtUsername" maxlength="100" id="txtUsername" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtUsername'] ?>" />
			
			
			</td>
          </tr>
		  <tr>
		  	<td colspan="1"></td><td><span id="txtUsernameFailed" class="<? echo $_SESSION['errors']['txtUsername'] ?>">You haven't entered a username or it isn't correct.</span></td>
		  </tr>
          <tr>
            <td width="46%"><label for="txtEmail">Email</label></td>
            <td width="54%"><input type="text" name="txtEmail" maxlength="250" id="txtEmail" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtEmail'] ?>" />
			
			
			</td>
          </tr>
		  <tr>
		  	<td colspan="1"></td><td><span id="txtEmailFailed" class="<? echo $_SESSION['errors']['txtEmail'] ?>">Invalid email address.</span></td>
		  </tr>
          <tr>
            <td width="46%"><label for="txtEmailChecker">Confirm Email</label></td>
            <td width="54%"><input type="text" name="txtEmailChecker" maxlength="250" id="txtEmailChecker" value="<?php echo $_SESSION['values']['txtEmailChecker'] ?>" />
			
			
			</td>
          </tr>
		   </tr>
		  <tr>
		  	<td colspan="1"></td><td><span id="txtEmailCheckFailed" class="<? echo $_SESSION['errors']['txtEmailChecker'] ?>">Email addresses don't match.</span></td>
		  </tr>
          </table>
	    </div>
		
		<div id="form_tbl_2">
	      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="form_txt">
          <tr>
            <td width="46%"><label for="txtOldPassword">Old Password</label></td>
            <td width="54%"><input type="password" name="txtOldPassword" maxlength="12" id="txtOldPassword" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtOldPassword'] ?>" />
			
			
			</td>
          </tr>
		   <tr>
		  	<td colspan="1"></td><td><span id="txtOldPasswordFailed" class="<? echo $_SESSION['errors']['txtOldPassword'] ?>">You haven't entered your old password or it isn't correct.</span></td>
		  </tr>
             <tr>
            <td width="46%"><label for="txtNewPassword">New Password</label></td>
            <td width="54%"><input type="password" name="txtNewPassword" maxlength="12" id="txtNewPassword" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtNewPassword'] ?>" />
			
			
			</td>
          </tr>
		    <tr>
		  	<td colspan="1"></td><td><span id="txtNewPasswordFailed" class="<? echo $_SESSION['errors']['txtNewPassword'] ?>">You haven't entered a new password</span></td>
		  </tr>
		  <tr>
            <td width="46%"><label for="txtNewPasswordChecker">Confirm New Password</label></td>
            <td width="54%"><input type="password" name="txtNewPasswordChecker" maxlength="12" id="txtNewPasswordChecker"  value="<?php echo $_SESSION['values']['txtNewPasswordChecker'] ?>" />
			
			
			</td>
          </tr>
		    <tr>
		  	<td colspan="1"></td><td><span id="txtNewPasswordCheckerFailed" class="<? echo $_SESSION['errors']['txtNewPasswordChecker'] ?>">New passwords entered don't match.</span></td>
		  </tr>
      </table>
   	  </div>
		<div id="form_tbl_4">
	      <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="46%"><input name="Rest" type="reset" class="button" value="Reset" />
              <input name="Submit" type="submit" class="button" value="Submit" /></td>
              <td width="54%">&nbsp;</td>
            </tr>
          </table>
      </div>
	  </form>
    </div>
  <!-- InstanceEndEditable -->
    <div id="txt_area2">
      <div id="p_link1"><img src="../images/p_link.jpg" width="19" height="19" class="br_link" /></div>
	  <div id="p_link2"><img src="../images/p_link.jpg" width="19" height="19" class="br_link" /><img src="../images/p_bl.jpg" class="bl_link" /></div>
    </div>
  </div>
  
  
  <div id="bottom">
    <div id="txt_area3">
      <div id="g_link1"><img src="../images/g_link.jpg" width="19" height="19" class="bl_link" /></div>
    </div>
	<div id="txt_area4">
	  <div id="p_link3"><img src="../images/p_link.jpg" width="19" height="19" class="br_link" /></div>
	  </div>
        </div>
</div>
</div>
</body>
<!-- InstanceEnd --></html>
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

It worked fine for me. I went to that page and there were no error messages.
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

Post by maddenuk »

thanks for getting back to me. Do you think it may be a browser cach problem?
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Post by Chalks »

It definately looks like a cache problem to me...

First time I went there, no errors. I hit submit a couple times, then left and came back. Still shows all errors. I'm new enough to php that I can't think of a solution, but I did read through your code, and the only thing that seemed a bit odd to me was:

Code: Select all

<form name="frmReset" action="./../scripts/validate_reset.php?validationType=reset" method="post" enctype="multipart/form-data">
Shouldn't it be "../../scripts/validate_reset.php"? Or does "./" refer to root, and I just didn't know that?


EDIT: I was using IE 6.0 when I viewed the page.
EDIT2: I did a hard refresh (clearing my cache), and the error messages were still there. Maybe the session isn't being destroyed?
Post Reply