Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6005141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:21:36+00:00 2026-05-23T01:21:36+00:00

I am using zend_form (part of Zend Framwork) to create a form and found

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:21:37+00:00Added an answer on May 23, 2026 at 1:21 am

    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 />\n")
        {
    
              // 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Zend_Form, how would I create form elements like this <input type=text name=element[1] value=/>
I am using zend form to create an radio button element. How do I
Using Zend_Form, how would I create form elements like this: <input type=text name=element[1] value=
Using Zend_Form, how would I create form elements like this: <input type=text name=element[0][name] value=
I'm using Zend Framework and Zend_Form to render my form. But as I found
About to create a form using Zend Form, all the form elements should have
I am new to zend. I am trying to create login form using zend
hi i am using zend form , i created a Zend_Form_Element_Radio element that have
I'm using Zend_Form from Zend Framework 1.10.6 to render a html form. In this
I'm using zend form in a non-zend project and I'm able to access Zend_Form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.