如何提交 Zend Dojo 子表单

发布于 2024-12-03 13:56:06 字数 1840 浏览 1 评论 0原文

我花了几个小时在网上寻找解决方案,但没有任何效果。

我有一个表单分为 2 个子表单(我无法让手风琴窗格工作),

如下所示:

$sfBase = new Zend_Dojo_Form_SubForm('base_info');
$sfBase->setName('base_info')
            ->setAction('/product/add?f=1');

$id = new Zend_Form_Element_Hidden('id');
$id->addFilter('Int')
      ->setAttrib('style', 'display:none');

$nom = new Zend_Dojo_Form_Element_TextBox('name');
$nom->setLabel('Nom du produit')
     ->setTrim(true)
     ->setValue("Entrez le nom")
     ->setPropercase(true);

$sdesc = new Zend_Dojo_Form_Element_TextBox('sdesc');
$sdesc->setLabel('Courte description du produit')
      ->setTrim(true)
      ->setValue("Description")
      ->setPropercase(true);

$sfBase->addElements(array($id, $nom, $sdesc);

$submitSubBase = new Zend_Dojo_Form_Element_SubmitButton('sub1');
$submitSubBase->setLabel('ok');
$sfBase->addElement($submitSubBase);

另一个子表单包含一些其他元素:

$sfComp = new Zend_Dojo_Form_SubForm('comp_info');
$sfComp->setName('comp_info')
       ->setAction('/product/add?f=2');
...
$submitSubComp = new Zend_Dojo_Form_Element_SubmitButton('sub2');
$submitSubComp->setLabel('envoyer');
$sfComp->addElement($submitSubComp);

$this->addSubForms(array('base_info' => $sfBase,
            'comp_info' => $sfComp
            ));

在我的控制器中,我显示整个实例化表单:

$this-> view->base = $form;

但每当我单击提交按钮时,什么也没有发生。 将单个提交按钮添加到表单(而不是子表单)

我尝试使用 setAction

$baseForm->setAction($this->view->url(
            array('controller' => 'Product', 'action' => 'add', 'id' => '1'), 'default', 
            true));

:但它是相同的,最后我将表单分为两个不同的 Zend_Form 而不是子表单,但这不是很干净......

所以尝试多页面表单、子表单和 dojo 容器失败,我不知道该怎么做,欢迎任何帮助!

谢谢

I have spent hours on the net to find a solution, but nothing works.

I have a form divided into 2 subForms (I couldn't get the accordion pane to work)

like this :

$sfBase = new Zend_Dojo_Form_SubForm('base_info');
$sfBase->setName('base_info')
            ->setAction('/product/add?f=1');

$id = new Zend_Form_Element_Hidden('id');
$id->addFilter('Int')
      ->setAttrib('style', 'display:none');

$nom = new Zend_Dojo_Form_Element_TextBox('name');
$nom->setLabel('Nom du produit')
     ->setTrim(true)
     ->setValue("Entrez le nom")
     ->setPropercase(true);

$sdesc = new Zend_Dojo_Form_Element_TextBox('sdesc');
$sdesc->setLabel('Courte description du produit')
      ->setTrim(true)
      ->setValue("Description")
      ->setPropercase(true);

$sfBase->addElements(array($id, $nom, $sdesc);

$submitSubBase = new Zend_Dojo_Form_Element_SubmitButton('sub1');
$submitSubBase->setLabel('ok');
$sfBase->addElement($submitSubBase);

and another subform which contains few other elements :

$sfComp = new Zend_Dojo_Form_SubForm('comp_info');
$sfComp->setName('comp_info')
       ->setAction('/product/add?f=2');
...
$submitSubComp = new Zend_Dojo_Form_Element_SubmitButton('sub2');
$submitSubComp->setLabel('envoyer');
$sfComp->addElement($submitSubComp);

$this->addSubForms(array('base_info' => $sfBase,
            'comp_info' => $sfComp
            ));

In my controller I display the entire instanciated form :

$this->view->base = $form;

but whenever I click on a submit button nothing happens. I tried placing a single submit button added to the form (not to a subForm)

with setAction :

$baseForm->setAction($this->view->url(
            array('controller' => 'Product', 'action' => 'add', 'id' => '1'), 'default', 
            true));

but it is the same, finally I divided the form into two distinct Zend_Form instead of subforms, but that is not very clean...

So having tried multi page forms, subForms and dojo containers unsuccessfully I don't know what to do, and any help would be welcome !

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很糊涂小朋友 2024-12-10 13:56:06

我不知道这是否有帮助,但这是我的答案。

如果 MAIN 表单未启用 Dojo,您是否在 init 方法中调用了 Zend_Dojo::enableForm() ? MAIN 表单是从 Zend_Dojo_Form 扩展的吗?如果它是从 Zend_Dojo_Form 扩展的,那么您不必调用 Zend_Dojo::enableForm()。

Dojo 表单通过使用 javascript 提交。您应该在客户端有一些 JavaScript 来处理服务器返回的响应。如果您的客户端没有 JavaScript 来处理这些返回,那么您将不会“看到”提交的结果。

尝试一下,使用 dojo 工具包编写一些 javascript,当它从服务器接收到某些内容时,它将创建一个警报框。这样,如果您单击提交按钮并出现警告框,您就会知道表单已提交。

I don't know if this will help at all but here is my answer.

If the MAIN form is not Dojo enabled, have you called Zend_Dojo::enableForm() in the init method? Is the MAIN form extending frorm Zend_Dojo_Form? If it's extending from Zend_Dojo_Form then you don't have to call Zend_Dojo::enableForm().

The Dojo forms submit through the use of javascript. You should have some javascript on the client side that can handle the responses from the server that will come back. If you don't have javascript on the client side to handle these returns, then you won't 'see' the results of the submit.

Try this, write some javascript using the dojo toolkit that will create an alert box when it receives something from the server. This way, if you click on the submit button and an alert box comes up you'll know that the form was submitted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文