HTML5 required attribute for some input forms

This commit is contained in:
Mikael Nordfeldth
2014-04-06 11:27:41 +02:00
parent 0777aa5487
commit a2a2105058
8 changed files with 29 additions and 12 deletions

View File

@@ -179,6 +179,7 @@ class HTMLOutputter extends XMLOutputter
* @param string $instructions instructions for valid input
* @param string $name name of the element; if null, the id will
* be used
* @param bool $required HTML5 required attribute (exclude when false)
*
* @todo add a $maxLength parameter
* @todo add a $size parameter
@@ -186,7 +187,7 @@ class HTMLOutputter extends XMLOutputter
* @return void
*/
function input($id, $label, $value=null, $instructions=null, $name=null)
function input($id, $label, $value=null, $instructions=null, $name=null, $required=false)
{
$this->element('label', array('for' => $id), $label);
$attrs = array('type' => 'text',
@@ -195,6 +196,9 @@ class HTMLOutputter extends XMLOutputter
if (!is_null($value)) { // value can be 0 or ''
$attrs['value'] = $value;
}
if (!empty($required)) {
$attrs['required'] = 'required';
}
$this->element('input', $attrs);
if ($instructions) {
$this->element('p', 'form_guide', $instructions);
@@ -527,6 +531,7 @@ class HTMLOutputter extends XMLOutputter
* @param string $name name of textarea; if null, $id will be used
* @param int $cols number of columns
* @param int $rows number of rows
* @param bool $required HTML5 required attribute (exclude when false)
*
* @return void
*/
@@ -538,7 +543,8 @@ class HTMLOutputter extends XMLOutputter
$instructions = null,
$name = null,
$cols = null,
$rows = null
$rows = null,
$required = false
) {
$this->element('label', array('for' => $id), $label);
$attrs = array(