gpt4 book ai didi

zend-framework - 如何清除zend中两个表单页面上的一组错误

转载 作者:行者123 更新时间:2023-12-03 09:00:49 25 4
gpt4 key购买 nike

我有一个一页的网站,其中有两个单独的表单需要重新发布到同一页面,问题是,如果我提交一个表单,则在两个表单上都进行了错误检查,因此显示了两个表单的错误消息。我需要的是,如果提交表单一,则仅出现表单一的错误消息,而不是表单二。 zend有可能吗?

最佳答案

zend要做的不是问题-但这是您要解决的问题!
如果为表单提供一个隐藏字段,或者具有一个表单唯一的字段ID,则应该能够检查 Controller 中已提交的表单,然后告诉zend您要检查的表单。类似于以下内容的工作,它将检查ID为unique_form_one_field的字段,该字段显然仅应存在于表单1中,例如,这可能是隐藏字段:

// Get the forms:
$form1 = $this->_helper->formLoader('form_one');
$form2 = $this->_helper->formLoader('form_two');

// Check if there is a POST:
if (!$request->isPost())
{
// It isn't show the forms:
$this->view->form_one = $form1;
$this->view->form_two = $form2;
}
else
{
// It is, get the POST data:
$post_data = $request->getPost();

// Check if form one has been submitted:
if (isset($post_data['unique_form_one_field']))
{
// Check if form one is valid:
if (!$form1->isValid($post_data))
{
// Its got an error, display the forms again, form one will now be populated with the data and also the error messages:
$this->view->form_one = $form1;
$this->view->form_two = $form2;
}
else
{
// Form one was valid - do what you want to process it:
}
}
else
{
// Check if form two is valid:
if (!$form2->isValid($post_data))
{
// Its got an error, display the forms again, form two will now be populated with the data and also the error messages:
$this->view->form_one = $form1;
$this->view->form_two = $form2;
}
else
{
// Form two was valid - do what you want to process it:
}
}
}

关于zend-framework - 如何清除zend中两个表单页面上的一组错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4711520/

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