]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/htmloutputter.php
HTML5 required attribute for some input forms
[quix0rs-gnu-social.git] / lib / htmloutputter.php
index 369cd5936e6a5aa9a284ec9ff4bc751758733658..f1496768b12b0b540cb9f97594aec1d72459bc5f 100644 (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(