ZF-10564: Zend_View_Helper_FormText HTML5 Improvement

Description

Some of HTML5 features can be used today without worrying about browser support. One of these things is More info at http://diveintohtml5.org/forms.html

All I wanted to achieve is to have element The first thing came to my mind is to do like this:

$e = new Zend_Form_Element_Text('email'); $e->setAttrib('type', 'email');

Zend_View_Helper_FormText still renders it as May be a better way is to have all these new helpers Zend_View_Helper_FormEmail, Zend_View_Helper_FormDate, Zend_View_Helper_FormRange ... But lests consider the following patch for Zend_View_Helper_FormText:

Index: .

--- . (revision 664) +++ . (working copy) @@ -71,7 +71,9 @@ $endTag= '>'; }

  • $xhtml = '<input type="text"'
  • $type = $this->_getType($attribs);
  •  $xhtml = '<input type="' . $type . '"'
             . ' name="' . $this->view->escape($name) . '"'
             . ' id="' . $this->view->escape($id) . '"'
             . ' value="' . $this->view->escape($value) . '"'
    

    @@ -81,4 +83,29 @@

     return $xhtml;
    

    }

  • private function _getType(array $attribs)
  • {
  • if(array_key_exists('type', $attribs)) {
  • $allowed = array(
  • 'email',
  • 'number',
  • 'url',
  • 'range',
  • 'search',
  • 'color',
  • 'date',
  • 'week',
  • 'month',
  • 'time',
  • 'datetime',
  • 'datetime-local',
  • );
  • if(in_array($attribs['type'], $allowed)) {
  • return $attribs['type'];
  • }
  • }
  • return 'text';
  • } }

Comments

I'd recommend not having any restraint until ZF has full support for HTML5.