And*_*rew 3 zend-framework zend-form
提交表单时,请求中不会提交已禁用的表单字段.
因此,如果您的表单具有禁用的表单字段,那么它会让您Zend_Form::isValid()感到有点沮丧.
$form->populate($originalData);
$form->my_text_field->disabled = 'disabled';
if (!$form->isValid($_POST)) {
//form is not valid
//since my_text_field is disabled, it doesn't get submitted in the request
//isValid() will clear the disabled field value, so now we have to re-populate the field
$form->my_text_field->value($originalData['my_text_field']);
$this->view->form = $form;
return;
}
// if the form is valid, and we call $form->getValues() to save the data, our disabled field value has been cleared!
Run Code Online (Sandbox Code Playgroud)
无需重新填充表单,并创建重复的代码行,解决此问题的最佳方法是什么?
| 归档时间: |
|
| 查看次数: |
3677 次 |
| 最近记录: |