• <legend id='v6d8X'><style id='v6d8X'><dir id='v6d8X'><q id='v6d8X'></q></dir></style></legend>

      1. <small id='v6d8X'></small><noframes id='v6d8X'>

      2. <tfoot id='v6d8X'></tfoot>
        <i id='v6d8X'><tr id='v6d8X'><dt id='v6d8X'><q id='v6d8X'><span id='v6d8X'><b id='v6d8X'><form id='v6d8X'><ins id='v6d8X'></ins><ul id='v6d8X'></ul><sub id='v6d8X'></sub></form><legend id='v6d8X'></legend><bdo id='v6d8X'><pre id='v6d8X'><center id='v6d8X'></center></pre></bdo></b><th id='v6d8X'></th></span></q></dt></tr></i><div id='v6d8X'><tfoot id='v6d8X'></tfoot><dl id='v6d8X'><fieldset id='v6d8X'></fieldset></dl></div>
        • <bdo id='v6d8X'></bdo><ul id='v6d8X'></ul>

        多复选框的 Zend 表单从标签中删除输入

        时间:2023-05-29

          <small id='Kne1k'></small><noframes id='Kne1k'>

          • <legend id='Kne1k'><style id='Kne1k'><dir id='Kne1k'><q id='Kne1k'></q></dir></style></legend>

                <tbody id='Kne1k'></tbody>
                <bdo id='Kne1k'></bdo><ul id='Kne1k'></ul>
                  <i id='Kne1k'><tr id='Kne1k'><dt id='Kne1k'><q id='Kne1k'><span id='Kne1k'><b id='Kne1k'><form id='Kne1k'><ins id='Kne1k'></ins><ul id='Kne1k'></ul><sub id='Kne1k'></sub></form><legend id='Kne1k'></legend><bdo id='Kne1k'><pre id='Kne1k'><center id='Kne1k'></center></pre></bdo></b><th id='Kne1k'></th></span></q></dt></tr></i><div id='Kne1k'><tfoot id='Kne1k'></tfoot><dl id='Kne1k'><fieldset id='Kne1k'></fieldset></dl></div>
                  <tfoot id='Kne1k'></tfoot>

                • 本文介绍了多复选框的 Zend 表单从标签中删除输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 zend_form(Zend Framwork 的一部分)来创建一个表单,当我使用 Zend_Form 的多复选框元素(Zend_Form_Element_MultiCheckbox)添加一组复选框时发现输出的代码如下:

                  即输入在标签内.虽然代码在技术上是可以的,但就 W3c 而言,它违背了良好的做法,也不是我想要的方式,因为它使样式变得更加困难.我想要的是以下内容:

                  <label for="subjects-maths">数学<input type="checkbox" value="maths" id="subjects-maths" name="subjects[]">

                  <div><label for="subjects-english">英语<input type="checkbox" value="maths" id="subjects-english" name="subjects[]">

                  因此,如何将复选框输入移出标签,以及如何将 div 中的每个选项括起来.我在互联网上查看了许多所谓的解决方案页面,但没有一个适用于多复选框,因为它只针对周围的标签(即在本例中会说主题的标签),而不是实际的选项标签和输入.

                  请帮忙.

                  谢谢保罗

                  解决方案

                  看来最好的解决方案是基于 squirrel 的上述答案.由于标签内的输入是硬编码的,因此最好的解决方案是改变这种行为.您可以通过修改 Zend_View_Helper_FormRadio 类或用您自己的自定义视图标题覆盖它来完成此操作.我会推荐自定义标头选项,因为修改 zend 框架将是一个坏主意,因为每次更新框架时都需要更新,对使用该框架副本的任何人或任何项目产生影响等.通过使用自定义帮助程序将特定于项目,它不会影响其他任何事情,也不会受到更新框架的影响(但是,如果框架更新更改了某些行为,您可能会发现需要更新帮助程序).我所做的运行良好的是:

                  1 - 在库中创建了一个模型/模块,我调用了我的网站.这首先涉及在库中创建一个与模型同名的文件夹.因此我有图书馆>网站

                  忘了说您需要通过 bootstrap 或 application.ini 注册插件库.我发现这是最简单的添加:

                  autoloaderNamespaces[] = "网站_"

                  应用程序命名空间下的任何位置

                  2 - 我为类 Website_View_Helper_FormRadio 创建了相关的子文件夹和文件,它将覆盖 Zend_View_Helper_FormRadio.因此文件夹和文件结构是

                  website > view > helper > FormRadio.php

                  3 - 然后我将 formRadio 函数的内容从 Zend_View_Helper_FormRadio 复制到类中的 Website_View_Helper_FormRadio 中.然后我用松鼠引用的代码修改它,因此从 Zend_View_Helper_FormRadio 继承的 Website_View_Helper_FormRadio 类像这样:

                  class Website_View_Helper_FormRadio 扩展 Zend_View_Helper_FormRadio{public function formRadio($name, $value = null, $attribs = null, $options = null, $listsep = "<br/>
                  "){//Zend_View_Helper_FormRadio 中 formRadio 函数的代码//修改自松鼠引用的代码}}

                  然后,这为我们提供了我们自己的类副本,其中包含从 FormRadio 元素的 Zend 版本继承的修改后的代码.

                  您现在可以像平常一样使用 Zend Form Radio 元素,它将使用我们的改进

                  请注意,如果您希望对 MultiCheckbox 或复选框具有相同的效果,则需要使它们使用我们的表单收音机版本,因为这些元素使用表单收音机作为基础.为此,我们在我们的库中创建了我们自己的这些版本,并使它们从我们的版本继承.因此,对于 multicheckbox,我们需要以下内容:

                  library > website > view > helper > FormMultiCheckbox.php

                  将是 Zend_View_Helper_FormMultiCheckbox 的副本

                  然后替换该行:

                  class Zend_View_Helper_FormMultiCheckbox 扩展 Zend_View_Helper_FormRadio

                  与:

                  class Website_View_Helper_FormMultiCheckbox 扩展了 Website_View_Helper_FormRadio

                  我希望对某人有所帮助.

                  I am using zend_form (part of Zend Framwork) to create a form and found when I add a set of checkboxes using Zend_Form's multicheckbox element (Zend_Form_Element_MultiCheckbox) the code that is outputted like so:

                  <label for="subjects-maths">
                      <input type="checkbox" value="maths" id="subjects-maths" name="subjects[]">
                      Maths
                  </label>
                  <label for="subjects-english">
                      <input type="checkbox" value="maths" id="subjects-english" name="subjects[]">
                      English    
                  </label>
                  

                  I.e. the input is inside the label. Whereas the code is technically ok it is against good practice as far as the W3c see it and is also not the way I want it as it makes styling harder. What I want is the following:

                  <div>
                      <label for="subjects-maths">        
                          Maths
                      </label>
                      <input type="checkbox" value="maths" id="subjects-maths" name="subjects[]">
                  </div>
                  <div>
                      <label for="subjects-english">            
                          English    
                      </label>
                      <input type="checkbox" value="maths" id="subjects-english" name="subjects[]">
                  </div>
                  

                  Therefore how do I move the checkbox input out of the label and how do I surround each option in divs. I have looked at many pages on the internet of so called solutions but none work on multicheckboxes as it only targets surrounding labels (i.e the one that would say subjects in this example) not the actual options labels and inputs.

                  Please help.

                  Thanks Paul

                  解决方案

                  It appears the best solution is based on the answer above by squirrel. As the input being inside a label is hard coded the best solution is to change this behavour. You can either do this by modifying the Zend_View_Helper_FormRadio class or override it with your own custom view header. I would recommend the custom header option as modifying the zend framework would be a bad idea as it would need updating everytime you updated the framework, have an effect on anyone or any project using that copy of the framework etc. By using a custom helper it will be specific to the project and it will not affect anything else nor will it be affected by updating the framework (however you may find you need to update the helper if the framework update has changed some behaviours). What I did which is working well is:

                  1 - Created a model/module in the library, I called mine website. This first involves creating a folder in the library the same name as the model. Thus I have library > website

                  Edit: Forgot to say you will need to register the plugin library either via the bootstrap or application.ini. I find it is easiest just add:

                  autoloaderNamespaces[] = "Website_"

                  Anywhere below appnamespace

                  2 - I created the relevant subfolders and file for the class Website_View_Helper_FormRadio which will override Zend_View_Helper_FormRadio. Thus the folder and file stucture is

                  website > view > helper > FormRadio.php

                  3 - I then copied the contents of the formRadio function from Zend_View_Helper_FormRadio into Website_View_Helper_FormRadio within the class. I then modified it with the code that squirrel referred thus the Website_View_Helper_FormRadio class that inherits from Zend_View_Helper_FormRadio like so:

                  class Website_View_Helper_FormRadio extends Zend_View_Helper_FormRadio
                  {
                       public function formRadio($name, $value = null, $attribs = null, $options = null, $listsep = "<br />
                  ")
                      {
                  
                            // The code from the formRadio function in Zend_View_Helper_FormRadio with
                            // the modification from the code squirrel referred to
                  
                      }
                  }
                  

                  This then gives us our own copy of the class with our modified code that inherits from the zend version of the FormRadio element.

                  You can now just use the Zend Form Radio element like normal and it will use our improvements

                  Note if you wish to have the same effect on MultiCheckbox or checkbox you need to make these use our version of form radio as these elements use form radio as a basis. To do this we create our own versions of these in our library and make them inherit from our version. We would therefore have for multicheckbox the following:

                  library > website > view > helper > FormMultiCheckbox.php

                  Would be a copy of Zend_View_Helper_FormMultiCheckbox

                  Then replace the line:

                  class Zend_View_Helper_FormMultiCheckbox extends Zend_View_Helper_FormRadio
                  

                  with:

                  class Website_View_Helper_FormMultiCheckbox extends Website_View_Helper_FormRadio
                  

                  I hope that helps someone.

                  这篇关于多复选框的 Zend 表单从标签中删除输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么此邮件消息不能正确解码? 下一篇:如何使用 Zend 框架读取控制器上的 application.ini

                  相关文章

                  <small id='mBEs9'></small><noframes id='mBEs9'>

                      <bdo id='mBEs9'></bdo><ul id='mBEs9'></ul>
                    1. <legend id='mBEs9'><style id='mBEs9'><dir id='mBEs9'><q id='mBEs9'></q></dir></style></legend>

                    2. <tfoot id='mBEs9'></tfoot>
                    3. <i id='mBEs9'><tr id='mBEs9'><dt id='mBEs9'><q id='mBEs9'><span id='mBEs9'><b id='mBEs9'><form id='mBEs9'><ins id='mBEs9'></ins><ul id='mBEs9'></ul><sub id='mBEs9'></sub></form><legend id='mBEs9'></legend><bdo id='mBEs9'><pre id='mBEs9'><center id='mBEs9'></center></pre></bdo></b><th id='mBEs9'></th></span></q></dt></tr></i><div id='mBEs9'><tfoot id='mBEs9'></tfoot><dl id='mBEs9'><fieldset id='mBEs9'></fieldset></dl></div>