Maybe try putting this in a beforeRender() function in your Users
controller?:

if(!isset($this->viewVars['error'])) {
     $this->set('error', false);
}

On Apr 23, 8:24 pm, Stacey <[EMAIL PROTECTED]> wrote:
> hi all,
>
> i read a post in here about having a login form built into the default
> layout. it suggested using an element, so i created one. i'm having
> one small problem with variables, and i'm hoping someone can help me
> out. what i'm trying to accomplish, is having the login form in the
> right column...but, after they login, i want to replace the form with
> a logout button. so, i figured the default layout would be the best
> place for this logic.
>
> ok...here's the login element :
>
> <?php if (isset($error) && $error): ?>
> <p><div class="error_message">Incorrect <br/>Username/Password</div></
> p>
> <?php endif; ?>
> <h1>Login/Register</h1>
> <form class="loginform" action="<?php echo $html->url('/users/
> login'); ?>" method="post">
>     <p>
>     Username<br/>
>     <?php echo $html->input('User/username', array('id' =>
> 'user_username', 'size' => '40', 'class' => 'textbox')) ?>
>     <?php echo $html->tagErrorMsg('User/username', 'Username
> required') ?>
>     </p>
>     <p>
>     Password<br/>
>     <?php echo $html->input('User/passwd', array('id' =>
> 'user_passwd', 'size' => '40', 'type'=>"password", 'class' =>
> 'textbox')) ?>
>     <?php echo $html->tagErrorMsg('User/passwd', 'Password required') ?
>
>     </p>
>     <p><?php echo $html->checkbox("User/cookie");?>&nbsp;Remember
> Me<br/></p>
>
>     <p><input class="button" type="submit" value="Login" /></p>
>                 <p>
>                   <br/>
>                   [<a href="#">Forgot Password?</a>]<br>
>                   Not Registered? <a href="#">Sign Up!</a>
>                 </p>
> </form>
>
> the 'error' variable is being passed from the login function in my
> users controller...
>
>         function login()
>         {
>             $this->set('error', false);
>                 if(isset($this->params['data']))
>         {
>                 if ($this->params['data']['User']['username']=='')
>             {
>                 $this->User->invalidate('username');
>             }
>                 else if ($this->params['data']['User']['passwd']=='')
>             {
>                 $this->User->invalidate('passwd');
>             }
>             else
>             {
>               $this->set('error', true);
>             }
>             $auth_num = $this->othAuth->login($this->params['data']
> ['User']);
>                 $this->set('auth_msg', $this->othAuth->getMsg($auth_num));
>         }
>         }
>
> and, here is the call from my default.thtml:
>
> <?php echo $this->renderElement("login",array("error"=>$error)); ?>
>
> my problem is, i get an 'undefined variable : error' if the page is
> loaded from anywhere but the login function. i understand why this is
> happening, but i'm not sure how to fix it. i tried using isset above
> the call to renderElement, to try and set the variable to false if
> it's not valid, but it won't let me do that...and, i think that's not
> the right way anyway.
>
> can someone point me in the right direction to do this.
>
> thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to