ZF-10205: Zend_Form_Element_Note to allow arbatary text in forms

Issue Type: Improvement Created: 2010-07-22T04:20:17.000+0000 Last Updated: 2013-01-10T11:51:22.000+0000 Status: Resolved Fix version(s): - 1.12.2 (25/Feb/13)

Reporter: Jonathan Dunn (jmd) Assignee: Richard Tuin (richardtuin) Tags: - Zend_Form

  • After1.12.0
  • state:patch-ready-for-review
  • zf-crteam-padraic
  • zf-crteam-priority
  • zf-crteam-review

Related issues: - ZF-3518

Attachments: - Note.php


Can Zend/Form/Element/Note.php be added to allow for arbatary text to be added in forms. Example of its use would be to allow a Username to be displayed as non-editable text along side editable text boxes such as Email/Password/Name but have decorators still applied.

class Zend_Form_Element_Note extends Zend_Form_Element_Xhtml
public $helper = 'formNote';


Posted by Peter Sharp (stryks) on 2010-07-22T15:51:37.000+0000

Isn't this just a textbox with ...

$element->setAttrib('disabled', 'disabled');

Or is this something else?

Posted by Jonathan Dunn (jmd) on 2010-07-23T02:24:49.000+0000

not really, there are many cases where a text box disabled would still not be appropriate.

Posted by Peter Sharp (stryks) on 2010-07-23T07:35:48.000+0000

Sorry, I didn't really say what I meant to.

It was more a question. What output did you want the element to generate? It's just not very clear what the new element is going to achieve in terms of output.

Posted by Richard Tuin (richardtuin) on 2010-11-19T14:10:36.000+0000

It would make sense to implement this new form element, as displaying a value only can't be solved with decorators.

I have attached the suggested implementation with the associated unit test as a patch.

Posted by Kai Uwe (kaiuwe) on 2010-11-20T08:29:18.000+0000

@Richard Tuin ??I have attached the suggested implementation with the associated unit test as a patch.??

You forgot something: Your note element loses the value after sending the form!

Here's an example to reproduce:

<pre class="highlight">
// View
$view = new Zend_View();

// Form
$form = new Zend_Form();

// Info text
$form->addElement('note', 'info', array(
    'value' => '

If you are already a registered customer, please sign in.


// Button
$form->addElement('submit', 'submit', array(
    'label' => 'Send',

if (isset($_POST['submit']) && $form->isValid($_POST)) {
    // ...

echo $form->render($view);

The solution: override the method "isValid".

<pre class="highlight">
 * Element to show an HTML note
 * @category   Zend
 * @package    Zend_Form
 * @subpackage Element
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (<a href=""></a>)
 * @license    <a href=""></a>     New BSD License
 * @version    $Id$
class Zend_Form_Element_Note extends Zend_Form_Element_Xhtml
     * Default form view helper to use for rendering
     * @var string
    public $helper = 'formNote';
     * Validate element value (pseudo)
     * There is no need to reset the value
     * @param  mixed $value Is always ignored
     * @param  mixed $context Is always ignored
     * @return boolean Returns always TRUE
    public function isValid($value, $context = null)
        return true;

Posted by Christoph Löffler ( on 2010-11-22T13:09:01.000+0000

I received these files from Kaiuwe, who cannot upload them atm.

Posted by Richard Tuin (richardtuin) on 2010-11-23T12:48:13.000+0000

@Kai Uwe Thank you for your correction.

As for now, no new components will be added to ZF1. I'll will be introduced in ZF 2.0. Changing the fix version to next major.

A 2.0 version of this component should be developed.

Posted by Kai Uwe (kaiuwe) on 2010-12-19T13:17:32.000+0000

New version:

<pre class="highlight">
 * Ignore flag (used when retrieving values at form level)
 * @var bool
protected $_ignore = true;

Posted by Frank Brückner (frosch) on 2013-01-10T11:51:22.000+0000

Fixed on trunk (25208) and release-1.12 (25209)

Thanks to Richard and Kai!

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.