我需要添加一个变量以在窗口小部件区域的窗体中显示为默认值,我已设置过滤器以根据下拉列表中的其他名称选择单个值。 我已将选定的数据设置为会话。从该会话中我已将该数据提取到操作文件中。我想在表单下拉列表中显示所选数据,而不创建提交事件。
表单显示在下面
public function configure() {
//the dropdown
$cost_range[''] = '-- Please select --';
for ($i = 0; ($i <= 100); $i++) {
$cost_range[$i] = $i;
}
$this->setWidgets(array(
'user_id' => new sfWidgetFormDoctrineChoice(array('model' => 'Person', 'add_empty' => '-- Please select --'), array('onchange' => 'filerUnitCostByName()', 'id' => 'user_id')),
//widget I need to dispaly the seleted value
'unit_cost' => new sfWidgetFormSelect(array('choices' => $cost_range), array('id'=>'unit_cost')),
));
$this->widgetSchema['user_id']->addOption('order_by',array('name','asc'));
$this->setValidators(array(
'user_id' => new sfValidatorString(array(), array('required' => 'User is required')),
));
$post_validator = new sfValidatorAnd();
$post_validator->addValidator(new sfValidatorCallback(array('callback' => array($this, 'checkPostValidations'))));
$this->validatorSchema->setPostValidator($post_validator);
$this->validatorSchema->setOption('allow_extra_fields', true);
$this->validatorSchema->setOption('filter_extra_fields', false);
$this->widgetSchema->setNameFormat('cost[%s]');
}
行动档案
public function execute($request) {
$contributionService = $this->getContributionService();
$this->form = new UnitCostForm();
$this->valueSet = $contributionService->getCostCenterList();
$this->userList = $contributionService->getUserLists();
//get value from session
$this->unitCost = $this->getUser()->getAttribute('unit_cost');
//assign variable to session value
$value_lists = ($this->unitCost);
//select value from foreach
foreach($value_lists as $values)
{
echo $values['unit_cost'];
}
这是我从数组中获取数据然后转到foreach以选择单个值的位置。 我想在表单中显示单个值而不提交。 我该怎么办?