QFC: hierselect default values ?

From: Date: Mon, 08 Mar 2004 19:38:23 +0000
Subject: QFC: hierselect default values ?
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-11156@lists.php.net to get a copy of this message
I fail to apply default values to a hierselect element in a QFC (no problem with other types of elements, though) A simple test case based on a doc example: <?php require_once 'HTML/QuickForm/Controller.php'; // Load some default action handlers require_once 'HTML/QuickForm/Action/Submit.php'; require_once 'HTML/QuickForm/Action/Display.php'; class SimplePage extends HTML_QuickForm_Page { function buildForm() { $this->_formBuilt = true; $this->addElement('header', null, 'Controller example 1: a simple form'); $main = array(); $secondary = array(); $main[0] = "England"; $main[1] = "Scotland"; $main[2] = "USA"; $secondary[0][0] = "London"; $secondary[0][1] = "Manchester"; $secondary[0][2] = "Liverpool"; $secondary[1][3] = "Edinburgh"; $secondary[1][4] = "Glasgow"; $secondary[2][5] = "Fort Worth"; $secondary[2][6] = "Boston"; $secondary[2][7] = "Los Angles"; $sel =& $this->addElement('hierselect', 'location', 'Location:'); $sel->setMainOptions($main); $sel->setSecOptions($secondary); // Bind the button to the 'submit' action $this->addElement('submit', $this->getButtonName('submit'), 'Send'); $this->applyFilter('tstText', 'trim'); $this->addRule('tstText', 'Pretty please!', 'required'); $this->setDefaultAction('submit'); } } class ActionProcess extends HTML_QuickForm_Action { function perform(&$page, $actionName) { echo "Submit successful!<br>\n<pre>\n"; var_dump($page->exportValues()); echo "\n</pre>\n"; } } $page =& new SimplePage('page1'); // We actually add these handlers here for the sake of example // They can be automatically loaded and added by the controller $page->addAction('display', new HTML_QuickForm_Action_Display()); $page->addAction('submit', new HTML_QuickForm_Action_Submit()); // This is the action we should always define ourselves $page->addAction('process', new ActionProcess()); $controller =& new HTML_QuickForm_Controller('simpleForm'); $controller->addPage($page); $controller->setDefaults( array( "location[0]" => 1, "location[1]" => 2, ) ) ; $controller->run(); ?> I suspect that the problem are the numeric indexes 0 and 1. I use defaults on other groups with non-numeric element indexes, which works. (Following Bertrand's advice I am working on the latest CVS, which solved this problem for QF)

« previous php.pear.general (#11156) next »