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 4242610
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:27:56+00:00 2026-05-21T03:27:56+00:00

I have the following element being created in Zend Form: // Add the submit

  • 0

I have the following element being created in Zend Form:

    // Add the submit button
    $this->addElement('button', 'cancel', array(...)
    ));

Which creates a button element as expected. What if I want to create a button element with span tag nested inside like so:

<button ...> 
<span>Cancel</span> 
</button> 

Any ideas?

  • 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-21T03:27:57+00:00Added an answer on May 21, 2026 at 3:27 am

    The problem with the answers in the other question is that it renders the buttons translatable capability useless.

    Here’s my solution. It’s practically a copy of both Zend_Form_Element_Button and Zend_View_Helper_FormButton, with added functionality.

    The form element:

    class App_Form_Element_ButtonPadded
        extends Zend_Form_Element_Button
    {
        public $helper = 'formButtonPadded';
    
        public function init()
        {
            $this->getView()->addHelperPath( 'App/View/Helper', 'App_View_Helper' );
        }
    }
    

    The view helper:

    class App_View_Helper_FormButtonPadded
        extends Zend_View_Helper_FormElement
    {
    
        public function formButtonPadded( $name, $value = null, $attribs = null )
        {
            $info    = $this->_getInfo( $name, $value, $attribs );
            extract( $info ); // name, id, value, attribs, options, listsep, disable, escape
    
            // Get content
            $content = '';
            if( isset( $attribs[ 'content' ] ) )
            {
                $content = $attribs[ 'content' ];
                unset( $attribs[ 'content' ] );
            } else {
                $content = $value;
            }
    
            // Ensure type is sane
            $type = 'button';
            if( isset( $attribs[ 'type' ] ) )
            {
                $attribs[ 'type' ] = strtolower( $attribs[ 'type' ] );
                if( in_array( $attribs[ 'type' ], array( 'submit', 'reset', 'button' ) ) )
                {
                    $type = $attribs[ 'type' ];
                }
                unset( $attribs[ 'type' ] );
            }
    
            // build the element
            if( $disable )
            {
                $attribs[ 'disabled' ] = 'disabled';
            }
    
            $content = ( $escape ) ? $this->view->escape( $content ) : $content;
    
            $xhtml = '<button'
                    . ' name="' . $this->view->escape( $name ) . '"'
                    . ' id="' . $this->view->escape( $id ) . '"'
                    . ' type="' . $type . '"';
    
            // add a value if one is given
            if( !empty( $value ) )
            {
                $xhtml .= ' value="' . $this->view->escape( $value ) . '"';
            }
    
            $paddingTag = 'span';
            if( isset( $attribs[ 'paddingTag' ] ) )
            {
                $paddingTag = strtolower( (string) $attribs[ 'paddingTag' ] );
                $paddingTag = strlen( $paddingTag ) ? $paddingTag : 'span';
                unset( $attribs[ 'paddingTag' ] );
            }
    
            $paddingTagRepeat = 1;
            if( isset( $attribs[ 'paddingTagRepeat' ] ) && $attribs[ 'paddingTagRepeat' ] >= 0 )
            {
                $paddingTagRepeat = (int) $attribs[ 'paddingTagRepeat' ];
                unset( $attribs[ 'paddingTagRepeat' ] );
            }
    
            $paddingStartTag = '<' . $paddingTag . '>';
            $paddingEndTag = '</' . $paddingTag . '>';
            $content = str_repeat( $paddingStartTag, $paddingTagRepeat ) . 
                       $content .
                       str_repeat( $paddingEndTag, $paddingTagRepeat );
    
            // add attributes and close start tag
            $xhtml .= $this->_htmlAttribs( $attribs ) . '>';
    
            // add content and end tag
            $xhtml .= $content . '</button>';
    
            return $xhtml;
        }
    }
    

    Possible usage:

    $paddedButton = new App_Form_Element_ButtonPadded( array(
        'type' => 'submit',
        'label' => 'Your possibly translatable label',
        'paddingTag' => 'span',
        'paddingTagRepeat' => 2 // I've had to use double span's inside the button for my app
    ) );
    

    Improvements welcomed.

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

Sidebar

Related Questions

I have the following element which specifies the size=15. However the rendered element, which
I have the following click event $(.element).click(function() { var idNum = $(this).getID; $('#new-'+idNum).fadeIn(); });
I have the following code, which will output the child-elements of the weather element.
Say I have the following element: <p id=thingy>Here is some <em>emphasized</em> text!</p> In a
I have the following jQuery: $(document).ready(function () { $(.element).draggable(); $(.element).droppable({ drop: function () {
In python I have the following function: def is_a_nice_element(element, parameter): #do something return True
I have the following HTML <select> element: <select id=leaveCode name=leaveCode> <option value=10>Annual Leave</option> <option
I have the following code; // open the modal when an element with a
I have the following: $(document).ready(function() { var myIframe = document.getElementById('myIframe'); var element = myIframe.contentDocument.createElement('script');
I have a Ruby hash with variables: a two-element array of strings an integer

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.