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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:10:46+00:00 2026-05-17T15:10:46+00:00

Is there some method that accepts inserting custom html without having to actually add

  • 0

Is there some method that accepts inserting custom html without having to actually add form controls, even if they’re hidden and making my html a decorator?

I’m looking for something like:

$this->addCustomElement( array(
'div', 
'body' => '<p>inner text</p>'
) );

I need something short and quick, I don’t want to create a new class or something overkill.

  • 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-17T15:10:47+00:00Added an answer on May 17, 2026 at 3:10 pm

    Well it’s really as simple as this:

    $note = new Zend_Form_Element('note');
    $note->helper = 'formNote';
    $note->setValue('<b>hi</b>');
    $form->addElement($note);
    

    But the problem is that when you submit the form, the form calls $note->isValid(), which overrides the value, so if there are errors with the form, the next time you display it, the custom HTML won’t be shown. There are two easy ways to fix this, the first is to override isValid() in your Form class like this:

    public function isValid($data)
    {
        $note = $this->note->getValue();
        $valid = parent::isValid($data);
        $this->note->setValue($note);
        return $valid;
    }
    

    But personally I find this kinda hackish way, and prefer the second option. That is to write a very simple class (this should really be part of Zend itself, I have no idea why it isn’t, since it includes a formNote view helper, but no element that uses it):

    class My_Form_Element_Note extends Zend_Form_Element_Xhtml
    {
        public $helper = 'formNote';
        public function isValid($value, $context = null) { return true; }
    }
    

    Then you just have to do:

    $note = new My_Form_Element_Note('note');
    $note->setValue('<b>hi</b>');
    $form->addElement($note);
    

    And everything will just work.

    Other options include doing some black magic with decorators, but I really recommend you to not go down that path.

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

Sidebar

Related Questions

I want to create a web method that accepts a List of custom objects
Is there any way to redefine a class or some of its methods without
I have a python webapp which accepts some data via POST. The method which
Is it possible to create a dbus method that accepts multiple arguments? I wish
Here's the situation. I have a base class which implements a method that accepts
I have a interface that defines some methods with attributes. These attributes need to
Is there some means of querying the system tables to establish which tables are
Is there some way I can use URLs like: http://www.blog.com/team-spirit/ instead of http://www.blog.com/?p=122 in
Is there some built-in way to share files between Xen guests? I don't currently
Is there some way to block access from a referrer using a .htaccess file

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.