solution: Formbuilder and quickform controller processing
| From: | Andrew Wooldridge | Date: | Tue, 14 Jun 2005 15:31:03 +0000 |
| Subject: | solution: Formbuilder and quickform controller processing | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-19617@lists.php.net to get a copy of this message | ||
I solved my own problem. Here's the stub code for the solution for the
purposes of sharing the knowledge. I made $fb a public member, then just
assigned whatever FormBuilder-built form I used in $this class to public
member $fb at the end of buildForm().
Inside the ActionProcess perform() method, I referenced this fb object as
&$page->fb in order to use it for processing (e.g. Adding data to the
database).
Controller instantiation code is not affected, but you must have the
convention of assigning $fb in the buildForm of every page. -A
Selective code listing:
class PageFirst extends HTML_QuickForm_Page
{
public $fb;
function buildForm()
{
$this->_formBuilt = true;
$config = parse_ini_file('DataObject.ini',TRUE);
foreach($config as $class=>$values) {
$options = &PEAR::getStaticProperty($class,'options');
$options = $values;
}
$do_ind = DB_DataObject::factory('IND');
$do_ind->debugLevel(1);
$do_gp = DB_DataObject::factory('GP');
#ALSO INCLUDE HERE: indname and address
$do_ind->fb_createSubmit = false;
$do_gp->fb_createSubmit = false;
$fb_ind = DB_DataObject_FormBuilder::create($do_ind);
$fb_gp = DB_DataObject_FormBuilder::create($do_gp);
//next line: something I have to do if i want the form to add to the
database
//if the form doesn't have a primary key
$fb_gp->forceQueryType(DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEINSERT);
$fb_ind->forceQueryType(DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEINSERT);
$fb_ind->useForm($this);
$form = $fb_ind->getForm();
# $fb_gp->useForm($form);
# $fb_gp->useForm($this);
# $form = $fb_gp->getForm();
$this->setDefaultAction('next');
$this->addElement('submit', $this->getButtonName('next'),
'Next
>>');
$this->addElement('submit', $this->getButtonName('display'),
'Display');
$this->fb =& $fb_ind;
}
}
class ActionProcess extends HTML_QuickForm_Action
{
function perform(&$page, $actionName)
{
echo "Submit successful?<br>\n<pre>\n";
var_dump($page->controller->exportValues());
echo "\n</pre>\n";
if($page->validate()) {
$page->process(array(&$page->fb, 'processForm'), false);
}
}
}
$cont =& new HTML_QuickForm_Controller('History and Information');
$cont->addPage(new PageFirst('page1'));
#$cont->addPage(new PageSecond('page2'));
#$cont->addPage(new PageThird('page3'));
// We actually add these handlers here for the sake of example
// They can be automatically loaded and added by the controller
$cont->addAction('submit', new HTML_QuickForm_Action_Submit());
$cont->addAction('display', new HTML_QuickForm_Action_Display());
$cont->addAction('next', new HTML_QuickForm_Action_Next());
$cont->addAction('back', new HTML_QuickForm_Action_Back());
$cont->addAction('jump', new HTML_QuickForm_Action_Jump());
// This is the action we should always define ourselves
$cont->addAction('process', new ActionProcess());
$cont->run();