For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > May 2005 > problem with quickform catching all POSTs









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author problem with quickform catching all POSTs
Richard Harding

2005-05-02, 3:58 pm

I have a quickform for a login form that I am using with smarty. I also
have a custom form that appears on a page along with the login
quickform. What I do on my forms is test the POST to see either what the
submit button value is or for a specific field to see which form has
been posted. The quickform form always gets called though and it's
messing with the page load.

The problem seems to be I have a page redirect if the form validates,
but it is redirecting every time I submit the other form which it seems
it shouldn't do because there is no valid login submitted.

Can anyone enlighten me to what is going on and how I might correct it?
Below is the code to the login form that is a function in a class
extending quickform. If I comment out the call to this function the
other form works just fine.

Thanks

Rick


Function creating the form:
function show_login_form($smarty) {
//$smarty->debugging = true;

if( isset( $_SESSION['UN'] ) ) {

// marked that they are logged in
$smarty->assign( 'login', true );
$smarty->assign( 'Session', $_SESSION );

} else {
// add the elements to the form
$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->addRule('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
header('Location: index.php' );
exit;

}// end if form validated
else {
$smarty->assign( 'login', false );
$this->accept( $renderer );
$smarty->assign( 'form_data', $renderer->toArray() );
//$smarty->display( 'login_form.tpl' );
}// end if form did not validate

}// end else the person is not logged in

}// end function show_login_form
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com