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

  • SEARCH
  • Home
  • 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 199707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:02:49+00:00 2026-05-11T17:02:49+00:00

I have a button element that I’ve created like so: $submit = new Zend_Form_Element_Button(‘submit’);

  • 0

I have a button element that I’ve created like so:

$submit = new Zend_Form_Element_Button('submit');
$submit->setLabel('My Button');
$submit->setDecorators(array(
    'ViewHelper',
     array('HtmlTag', array('tag' => 'li'))
));
$submit->setAttrib('type', 'submit');

This generates the following HTML:

<li>
    <label for="submit" class="optional">My Button</label> 
    <button name="submit" id="submit" type="submit">My Button</button>
</li>

I would like to wrap the inside of the button with a <span>, like this:

<button...><span>My Button</span></button>

What is the best way to do this using Zend_Form?

  • 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-11T17:02:49+00:00Added an answer on May 11, 2026 at 5:02 pm

    I have tried and, ultimately, failed to achieve this myself using the same approach. It would seem that the easiest way to do this would be to do:

    ...
    $submit->setLabel('<span>My Button</span>');
    ...
    

    However, the span will be escaped. It’s perfectly possible to turn off the escaping of a lable decorator, however, adding a label decorator renders the output incorrectly, for instance:

    $decorator = array(
        array('ViewHelper'),
        array('HtmlTag', array('tag' => 'li')),
        array('Label', array('escape' => false))
    );
    
    $submit = new Zend_Form_Element_Button('submit');
    $submit->setLabel('<span>My Button</span>');
    $submit->setDecorators($decorator);
    $submit->setAttrib('type', 'submit');
    

    … renders:

    <label for="submit" class="optional"><span>My Button</span></label>
    <li>
        <button name="submit" id="submit" type="submit">&lt;span&gt;My Button&lt;/span&gt</button>
    </li>
    

    …which, aside from being semantically incorrect (easily fixable), is still escaping the span tags inside the element.

    So what do you do?

    Well I think the best approach (and this is my meta-advice when it comes to tight control over Zend_Form rendering) is to use the ViewScript decorator.

    $submit = new Zend_Form_Element_Button('submit');
    $submit->setLabel('My Button');
    $submit->setDecorators(array(array('ViewScript', array('viewScript' => '_submitButton.phtml'))));
    $submit->setAttrib('type', 'submit');
    

    …then in _submitButton.phtml define the following:

    <li>
        <?= $this->formLabel($this->element->getName(), $this->element->getLabel()); ?>
        <button 
        <?php 
    
        $attribs = $this->element->getAttribs();
    
        echo
        ' name="' . $this->escape($this->element->getName()) . '"' .
        ' id="' . $this->escape($this->element->getId()) . '"' . 
        ' type="' . $this->escape($attribs['type']) . '"';
        ?>
        <?php
    
        $value = $this->element->getValue();
    
        if(!empty($value))
        {
            echo ' value="' . $this->escape($this->element->getValue()) . '"';
        }
        ?>
        >
        <span>
        <?= $this->escape($this->element->getLabel()); ?>
        </span>
        </button>
    </li>
    

    The _submitButton.phtml file will need to be in a view script directory (you might be best adding a specific one for your form decorators using $view->addScriptPath('/path/to/my/form/decorators')).

    This should render what you’re looking for. I’ve only just started looking at the ViewScript decorator due to flexibility issues I’m experiencing in work. You’ll notice that my script isn’t that flexible, and certainly isn’t in BNF, given all the members that can be populated on the element object. That said, it’s a start and it solves your problem.

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

Sidebar

Related Questions

I have a button that I would like to disable when the form submits
I have an element that needs to behave like UIButton but it has several
hi i am using zend form , i created a Zend_Form_Element_Radio element that have
I have an element that looks something like this. <xsd:element name=container> <xsd:complexType> <xsd:choice minOccurs=0
I have an input element that's configured as a button (see code below). When
I have button, which fires an event, that deletes a record from the database.
I have a button set, and would like to set the width of each
I have an element that fades in, its the size of the page and
So i have one div element that i append on my DOM with a
I have created one gridview and use custom adapter for that. I added two

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.