0

View Helpers have some initial helpers, such as formButton and formText.

As the reference said:

formText($name, $value, $attribs): Creates an <input type="text" /> element.

But I find something not like it on my PC. I write below code in a view file:

<?php 
echo $this->formText('email', 'you@example.com', array('size' => 32));
?>

The HTML is as below:

<input type="text" name="email" id="email" value="you@example.com" size="32">

There isn't a '/' at the end.It should be :

<input type="text" name="email" id="email" value="you@example.com" size="32"/>

So is there something wrong? My version is ZF1.12 and PHP5.4.

roast_soul
  • 3,554
  • 7
  • 36
  • 73

2 Answers2

3

No. ZF checks whether the doctype you appended to the view is XHTML and adds the forward slash only if this is true.

Check out Zend_View_Helper_HtmlElement::getClosingBracket

if (!$this->_closingBracket) {
    if ($this->_isXhtml()) {
        $this->_closingBracket = ' />';
    } else {
        $this->_closingBracket = '>';
    }
}

return $this->_closingBracket;
danronmoon
  • 3,814
  • 5
  • 34
  • 56
1

It's not a bug. the output depends on your document's doctype. if it is an XHTML doctype it will output the /> otherwise it will output just the > to end the tag.

Check the Zend_View_Helper_FormText Class

....
// XHTML or HTML end tag?
    $endTag = ' />';
    if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
        $endTag= '>';
    }
....
Fouad Fodail
  • 2,653
  • 1
  • 16
  • 16