QuickForm Controller using Smarty getButtonName issue
| From: | Patrick Fehr | Date: | Wed, 23 Feb 2005 13:41:51 +0000 |
| Subject: | QuickForm Controller using Smarty getButtonName issue | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-17645@lists.php.net to get a copy of this message | ||
I have seen that people in here asking for
"QFC(QuickForm_Controller)combined with Smarty" help are VERY VERY lost.
And so am I :)
My Problem:
The Buttons are being set by getButtonName() so I don't know how to
use/place them in the template, so I've read:
http://pear.php.net/manual/en/package.html.html-quickform-controller.faq.php#package.html.html-quickform-controller.faq.actions.default
That didn't help a lot, Smarty doesn't seem to be dynamic and is not listed
under the Templates that work with the code that's posted there.
I was pretty desperate after all and print_r'ted $page and just took these
names for the buttons :)
Anyway there seems not to be one SINGLE tutorial on QuickFormController
using Smarty Template, obviously there are for QuickForm itself and that's
quite easy though, but for ever changing wizard pages (and so for every
Page class) you need a different tpl.
Saw that question here several times but no answers to it.
My approach seems to work fine, so I hope there is someone out there that
can take advantage of it:
-----------------------------8<------------------------------
class PageOne extends HTML_QuickForm_Page
{
var $_db;
var $_tpl;
function PageOne ($formName, $method = 'post', $target = '_self',
$attributes = null, &$db)
{
$this->HTML_QuickForm_Page($formName, $method, $target,
$attributes);
$this->_db =& $db;
$this->_tpl = 'reg_test_page1.tpl';
}
//the same for class PageTwo etc.
class ActionDisplay extends HTML_QuickForm_Action_Display
{
/*
DB is a DatabaseObjekt
TPL is a SmartyObjekt
*/
var $_db;
var $_tpl;
function ActionDisplay (&$db)
{
$this->_db =& $db;
}
function _renderForm(&$page)
{
global $menu;
$this->_tpl = new Page();
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($this->_tpl);
$renderer->setRequiredTemplate(
'{if $error}
<font color="red">{$label|upper}</font>
{else}
{$label}
{if $required}
<font color="red" size="1">*</font>
{/if}
{/if}'
);
$renderer->setErrorTemplate(
'{if $error}
<font color="orange" size="1">{$error}</font><br
/>
{/if}
{$html}'
);
$form_array =& $page->toArray();
$page->setRequiredNote(
'<span style="font-size:80%; color:red;">
*
</span>
<span style="font-size:80%; color:blue;">
field is necessary
</span>'
);
$page->accept($renderer);
echo "<pre style=\"background: #ffffff;\">";
var_dump($renderer->toArray());
echo "</pre>";
$this->_tpl->assign('form_data', $renderer->toArray());
//following are just assignings to the template with my own temp-class
$this->_tpl->setPageTitle(SITE_NAME.'- Anmeldung');
$this->_tpl->displayMenu($menu);
$this->_tpl->displayTemplate($page->_tpl);
}
}
----------------------------->8------------------------------
Well these are my 50cent, hope it helps someone out there.
Of course I am thankful for every hint about the button issue.
cheers
--
Patrick Fehr
Swiss Federal Institute Of Technology