gpt4 book ai didi

zend-framework - Zend 框架 : isValid() clears values from disabled form fields!

转载 作者:行者123 更新时间:2023-12-04 06:47:46 25 4
gpt4 key购买 nike

当您提交表单时,禁用的表单字段不会在请求中提交。

因此,如果您的表单有一个禁用的表单字段,那么使用 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!

无需重新填充表单和创建重复的代码行,解决此问题的最佳方法是什么?

最佳答案

您是否将元素设置为禁用,以便用户无法编辑其内容而只能看到它?如果是这样,只需将元素的只读属性设置为 true,我认为它会以这种方式工作。

关于zend-framework - Zend 框架 : isValid() clears values from disabled form fields!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2510923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com