Re: QuickForm_Controller and Smarty, session error
| From: | Trevan Devaun Richins | Date: | Thu, 24 Jun 2004 21:00:08 +0000 |
| Subject: | Re: QuickForm_Controller and Smarty, session error | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13320@lists.php.net to get a copy of this message | ||
Trevan Devaun Richins wrote:
Bertrand Mansion wrote:<?php require_once ('HTML/QuickForm.php'); require_once ('HTML/QuickForm/Renderer/ArraySmarty.php'); require_once ('HTML/QuickForm/Controller.php'); require_once ('HTML/QuickForm/Action/Display.php'); define('SMARTY_DIR', 'Smarty-2.6.3/libs/'); require_once (SMARTY_DIR.'Smarty.class.php'); // The session will be used to store the values session_start(); // we start up the smarty engine $smarty =& new Smarty; define('CONFIG_DIR', 'dir/'); $smarty->template_dir = CONFIG_DIR.'templates/'; $smarty->compile_dir = CONFIG_DIR.'templates_c'; $smarty->config_dir = CONFIG_DIR.'configs/'; $smarty->cache_dir = CONFIG_DIR.'cache/'; $smarty->force_compile = true; $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty); // We need to create a class for each page class edit_user extends HTML_QuickForm_Page {Trevan Devaun Richins wrote:Thanks for the reply, I modified my code with the ampersand but the error is still there. The HTML for the radio boxes are outputted correctly as: <input value="enabled" type="radio" id="qf_a09337" name="status" /><input value="disabled" type="radio" id="qf_b69b0a" name="status" checked="checked" /><input value="locked" type="radio" id="qf_746c7b" name="status" /> Where disabled is checked on this example. But if you load up the page, it will first display disabled as checked, and after you reload the page (not a hard reload), the locked option becomes selected. It happens EVERY time you reload it for the first time, yet the HTML looks fine. This error only occurs when it is being used with HTML_QuickForm_Controller. Plus, when you delete the session cookie that Controller creates, it will start the process over again. The HTML, though, looks fine, and there is no javascript. The error is duplicated at http://students.cs.byu.edu/~tdr32/LDAP_Admin/LDAP_Admin/. Thanks for the help. I am trying to just delet unnecessary stuff to find the error. Trevan This might help. This is my actual code for the page. I have deleted everything that is unnecessary.This is how I build my radio buttons. I use an external array that has the information of the radios (in $element_data). Then, I just loop through it and place it in a group. $element_data['enabled'] = 'enabled'; $element_data['disabled'] = 'disabled'; $element_data['radio_group']['locked'] = 'locked'; foreach($element_data['radio_group'] as $radio_value) { $radio_button[] = HTML_QuickForm::createElement('radio',null,null,null,$radio_value,null); } return HTML_QuickForm::createElement('group',$radio_button,'status',null,'');Try: $radio_button[] =& HTML_QuickForm::createElement('radio',null,null,$radio_value,$radio_value); Use an ampersand in front of your function name as well in order to keep the reference to the created elements/groups. Bertrand Mansion Mamasam
// two things needed in each class
// function buildForm and
// $this->_formBuilt = true
function buildForm()
{
// this is used to tell smarty which of the templates to use for this page
$this->_smarty_template = 'admin_edit';
// makes sure that this is only called once
$this->_formBuilt = true;
// This line asks the Form_Create to build the elements needed from the config file
$radio_button[] =& HTML_QuickForm::createElement('radio',null,null,null,'enabled',null);
$radio_button[] =& HTML_QuickForm::createElement('radio',null,null,null,'disabled',null);
$radio_button[] =& HTML_QuickForm::createElement('radio',null,null,null,'locked',null);
$this->addGroup($radio_button,'status',null,'');
}
}
class Display_Form extends HTML_QuickForm_Action_Display
{
var $page;
function _renderForm(&$page) {
global $smarty;
global $renderer;
$this->page =& $page;
$this->page->accept($renderer);
$smarty->assign('form', $renderer->toArray());
// This is for debugging only
ob_start();
print_r($renderer->toArray());
$smarty->assign('static_array', ob_get_contents());
ob_end_clean();
ob_start();
print_r($_SESSION);
$smarty->assign('session', ob_get_contents());
ob_end_clean();
// End of debugging section
switch ($this->page->getAttribute('id')) {
case 'edit_user':
$smarty->display($this->page->_smarty_template.'.tpl');
break;
}
}
}
$page1 =& new edit_user('edit_user');
// This creates the actual controller of the form
$controller =& new HTML_QuickForm_Controller('admin_edit');
$controller->addPage($page1);
$defaults = array('status' => 'disabled');
$controller->setDefaults($defaults);
$controller->addAction('display', new Display_Form());
$controller->run();
?>
Trevan