Issue Bug Closed

#67098Bug in TextfieldViewHelper for "required" tag

Markus Hölzle 05/22/15, 09:51 updated 10/02/18, 11:44

Description

There is a major bug in the TextfieldViewHelper (namespace TYPO3\CMS\Fluid\ViewHelpers\Form):
The parameter “required” will be casted as boolean:

    /**
     * Renders the textfield.
     *
     * @param bool $required If the field is required or not
     * @param string $type The field type, e.g. "text", "email", "url" etc.
     * @return string
     * @api
     */
    public function render($required = NULL, $type = 'text') {

But in the comparison the parameter is checked if it is not NULL:

if ($required !== NULL) {
    $this->tag->addAttribute('required', 'required');
}

So it is no matter if you call the function with “required = FALSE” or “required = TRUE”, because both is not “NULL”.

This should be:

    public function render($required = FALSE, $type = 'text') {
if ($required !== FALSE) {
    $this->tag->addAttribute('required', 'required');
}

Reviews 1