QuickForm Controller: how to bind custom action to a button?
| From: | Igor Antokhin | Date: | Fri, 23 Jan 2009 19:20:57 +0000 |
| Subject: | QuickForm Controller: how to bind custom action to a button? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-29635@lists.php.net to get a copy of this message | ||
I am new to PEAR and QuickForm Controller so please excuse my ignorance.
Now, to the problem:
I am creating a multi-page form, in the first (login) page the user must
enter his name/password. I want to provide a logout mechanism on the
following pages. This should be a button, clicking on it should destroy the session and re-display the first page. I create my custom logout
action, add it to my form, and in e.g. page 2 add the button (code below).
This works as expected when clicking the buttons, but if I press Enter on
the 2nd page, then instead of going to page 3 the logout action is
performed. What do I do wrong?
Thanks for your help,
Igor
===============Code===================
class Page2 extends HTML_QuickForm_Page {
function buildForm() {
...
$this->addElement( 'submit', $this->getButtonName('logout'), 'Log out');
$this->addElement( 'header', ... );
...
$buttons[] =& $this->createElement('submit', $this->getButtonName('back'), 'Back');
$buttons[] =& $this->createElement('submit', $this->getButtonName('next'), 'Next');
$buttons[] =& $this->createElement('reset', $this->getButtonName('clear'), 'Clear');
$this->addGroup( $buttons, 'buttons', '', ' ', false );
$this->setDefaultAction('next');
return;
}
}
class myActionLogout extends HTML_QuickForm_Action {
function perform( &$page, $actionName ) {
$page1 =& $page->controller->getPage( 'page1' );
session_destroy();
session_start();
return $page1->handle('jump');
}
}
$wizard =& new HTML_QuickForm_Controller( 'Wizard' );
$wizard->addPage( new Page1( 'page1' ) );
$wizard->addPage( new Page2( 'page2' ) );
....
$wizard->addAction( 'display', new myActionDisplay() );
....
$wizard->addAction( 'process', new myActionProcess() );
$wizard->addAction( 'logout', new myActionLogout() );
$wizard->run();