Re: question on HTML_Quickform error message & smarty
| From: | Justin Patrin | Date: | Mon, 14 Mar 2005 17:26:51 +0000 |
| Subject: | Re: question on HTML_Quickform error message & smarty | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18058@lists.php.net to get a copy of this message | ||
On Mon, 14 Mar 2005 12:23:20 -0500, Richard Harding <rick@ricksweb.info> wrote:
> I have a login form using HTML_Quickform and a smarty template. I seem
> to be having trouble getting the error message to show if the login
> fails. I have a custom rule that seems to be working according to the
> smarty debugger. I have error values set, but I can't seem to get them
> to show back in the form at all.
>
> Below is relevant code from both the php file, the .tpl, and the smarty
> debugger on a form submit
>
> Thanks for any help.
>
> Rick
>
> login.php (class extending HTML_Quickform):
> $this->addElement( 'header', 'login_header', 'Login' );
>
> $fields[] = &HTML_QuickForm::createElement( 'text',
> 'username', 'Username', array('size' => 15,
> 'maxlength' => 25 ) );
> $fields[] = &HTML_QuickForm::createElement( 'password',
> 'password', 'Password', array('size' => 15,
> 'maxlength' => 25 ));
>
> $this->addGroup($fields, 'fields', '<br />');
>
> $this->addElement( 'submit', 'login_button',
> 'Login' );
>
> $this->registerRule('login_user', 'callback',
> 'login_user', 'login');
>
> $this->addGroupRule('fields', 'Invalid
> Username/Password!', 'login_user');
>
> // set the renderer options
> $renderer = &new HTML_QuickForm_Renderer_ArraySmarty(
> $smarty );
>
> $renderer->setErrorTemplate( '{$html} {if $error}
> <span
> class="error">{$error}</span>
> {/if}' );
>
> if( $this->validate() ) {
>
> // marked that they are logged in
> $smarty->assign( 'login', true );
> $smarty->assign( 'Session', $_SESSION );
>
> }// end if form validated
> else {
> $smarty->assign( 'login', false );
> $this->accept( $renderer );
> $smarty->assign( 'form_data', $renderer->toArray() );
> }// end if form did not validate
>
> template user: login_form.tpl
> <form {$form_data.attributes}>
> <table cellpadding="0" cellspacing="0"
> border="0">
> <tr>
> <td><img src="{$Base_Path}images/left_arc.gif"
> class="no_space"/></td>
> <td align="center" bgcolor="#006600"
>
> width="100%"class="login_form_header">{$form_data.header.login_header}</td>
> <td><img src="{$Base_Path}images/right_arc.gif"
> class="no_space" /></td>
> </tr>
> </table>
> <div class="login_form" align="center">
> <span
> class="login_form_label">{$form_data.fields.username.label}</span>
> {$form_data.fields.username.html}
> <br />
> <span
> class="login_form_label">{$form_data.fields.password.label}</span>
> {$form_data.fields.password.html}
> <div align="center">
> <span
> class="login_form_label">{$form_data.login_button.label}</span>
> {$form_data.login_button.html}
> <br /><br />
> <hr />
> <br />
> <div>
> <a
> href="{$Base_Path}login.php?action=user_account">New User</a>
> <br />
> <a
> href="{$Base_Path}login.php?action=forgot_password">Forgot Login</a>
> </div>
> </div>
> </div>
> </form>
>
> smarty-debugger info:
> {$form_data}*Array (9)*
> *frozen* =>
> *javascript* => /empty/
> *attributes* => action="/index.php" method="post" na...
> *requirednote* => <span style="font-size:80%; color:#ff...
> *errors* => *Array (1)*
> *fields* => Invalid Username/Password!
> *hidden* => /empty/
> *header* => *Array (1)*
> *login_header* => Login
> *fields* => *Array (11)*
> *name* => fields
> *value* => *Array (2)*
> *username* => rharding
> *password* => testing
> *type* => group
> *frozen* =>
> *required* =>
> *error* =>
> *label* => <br />
> *separator* => /empty/
> *html* => <input size="15" maxlength="25" name=...
> *username* => *Array (8)*
> *name* => fields[username]
> *value* => rharding
> *type* => text
> *frozen* =>
> *required* =>
> *error* =>
> *label* => Username
> *html* => <input size="15" maxlength="25" name=...
> *password* => *Array (8)*
> *name* => fields[password]
> *value* => testing
> *type* => password
> *frozen* =>
> *required* =>
> *error* =>
> *label* => Password
> *html* => <input size="15" maxlength="25" name=...
> *login_button* => *Array (8)*
> *name* => login_button
> *value* => Login
> *type* => submit
> *frozen* =>
> *required* =>
> *error* =>
> *label* => /empty/
> *html* => <input name="login_button" value="Log...
>
I don't see anywhere in your Smarty template where you're outputting the error.
--
Justin Patrin