Forums / Developer / Post variables

Post variables

Author Message

Fabien Mas

Thursday 29 March 2007 5:56:46 am

I want to send a form to register a new user in the session variables, but It doesn't work
Sometimes the php code detect a my post variable "BtConnecter", sometimes not !
Is it because of the cache ?

Here my php code

...
include_once('extension/fichedecommunication/classes/iagmanifestation_user.php');

//-- init
$http =eZHttpTool::instance();


if($http->postVariable('BtConnecter')!="")
{	
 iagManifestation_User::CheckLogin($http->postVariable("TLogin"),$http->postVariable("TPassword"));
	$user= iagManifestation_User::CurrentUser();
	if (  $user )
	{	
		$http->headerVariable("Location","/fichedecommunication/manifestation");
	}
}

Here is a part of my iagManifestation_User class

        function CheckLogin($log,$passw)
	{			
		$http =& eZHttpTool::instance();	
		$db =& eZDB::instance();		
		$logArray = $db->arrayQuery("SELECT ID FROM iagManifestation_User WHERE Login='$log' AND Password='$passw';" );		
		if(count($logArray)>0 && $logArray[0]["ID"]>0)
		{							
			$http->setSessionVariable('iagManifestationUser', new iagManifestation_User($logArray[0]["ID"]));														
		}
		else
		{
			$http->setSessionVariable('iagManifestationUser', '');

		}		
	}
	function CurrentUser()
    {   
    	$http =eZHttpTool::instance();    	
    	$currentuser = $http->sessionVariable('iagManifestationUser');    	
        if (  get_class( $currentuser ) == strtolower('iagManifestation_User') )
        {                
            return $currentuser;
        }
        return ;
    }

Here is my template

{set-block scope=root variable=cache_ttl}0{/set-block}
<form method="post" action="" name="fmanifestationlogin">
<table cellpadding="8" cellspacing="10">
	<tr>
		<td>{'Login'|i18n( 'iagManifestation_manifestation' )}</td>
		<td><input type="text" name="TLogin" value="{$login}" /></td>
	</tr>
	<tr>
		<td>{'Mot de passe'|i18n( 'iagManifestation_manifestation' )}</td>
		<td><input type="password" name="TPassword" value="" /></td>
	</tr>
	<tr>
		<td></td>
		<td><input type="submit" name="BtConnecter" value="Se connecter" /></td>
	</tr>
</table>
</form>

Fabien Mas

Thursday 29 March 2007 6:10:08 am

It works now, but I had to change my session variable :
before I saved the object( iagManifestation_User )
Now I save the object ID and create a new user in the currentuser function