Revision: 2541
          https://sourceforge.net/p/mrbs/code/2541/
Author:   cimorrison
Date:     2012-10-30 10:56:16 +0000 (Tue, 30 Oct 2012)
Log Message:
-----------
Fixed some HTML5 validation issues

Modified Paths:
--------------
    mrbs/trunk/web/edit_entry.php
    mrbs/trunk/web/edit_users.php
    mrbs/trunk/web/functions.inc

Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2012-10-30 09:04:46 UTC (rev 2540)
+++ mrbs/trunk/web/edit_entry.php       2012-10-30 10:56:16 UTC (rev 2541)
@@ -189,10 +189,11 @@
                   'name'       => 'name',
                   'field'      => 'entry.name',
                   'value'      => $name,
+                  'type'       => 'text',
+                  'pattern'    => REGEX_TEXT_POS,
                   'disabled'   => $disabled,
                   'mandatory'  => TRUE,
-                  'maxlength'  => $maxlength['entry.name'],
-                  'attributes' => 'type="text" pattern="' . REGEX_TEXT_POS . 
'"');
+                  'maxlength'  => $maxlength['entry.name']);
                   
   generate_input($params);
 
@@ -634,19 +635,19 @@
     $is_integer_field = ($field['nature'] == 'integer') && ($field['length'] > 
2);
     if ($is_integer_field)
     {
-      $attributes = 'type="number" step="1"';
+      $params['type'] = 'number';
+      $params['step'] = '1';
     }
     else
     {
-      $attributes = 'type="text"';
+      $params['type'] = 'text';
+      if ($params['mandatory'])
+      {
+        // 'required' is not sufficient for strings, because we also want to 
make sure
+        // that the string contains at least one non-whitespace character
+        $params['pattern'] = REGEX_TEXT_POS;
+      }
     }
-    if ($params['mandatory'])
-    {
-      // 'required' is not sufficient for strings, because we also want to 
make sure
-      // that the string contains at least one non-whitespace character
-      $attributes .= ($is_integer_field) ? '' : ' pattern="' . REGEX_TEXT_POS 
. '"';
-    }
-    $params['attributes'] = $attributes;
     $params['field'] = "entry.$key";
     generate_input($params);
   }
@@ -1306,10 +1307,12 @@
       echo "<div>\n";
       $params = array('label'      => get_vocab("rep_num_weeks") . ":",
                       'name'       => 'rep_num_weeks',
+                      'type'       => 'number',
+                      'step'       => '1',
+                      'min'        => REP_NUM_WEEKS_MIN,
                       'value'      => $rep_num_weeks,
                       'suffix'     => get_vocab("weeks"),
-                      'disabled'   => $disabled,
-                      'attributes' => 'type="number" min="' . 
REP_NUM_WEEKS_MIN . '" step="1"');
+                      'disabled'   => $disabled);
       generate_input($params);
     
       echo "</div>\n";

Modified: mrbs/trunk/web/edit_users.php
===================================================================
--- mrbs/trunk/web/edit_users.php       2012-10-30 09:04:46 UTC (rev 2540)
+++ mrbs/trunk/web/edit_users.php       2012-10-30 10:56:16 UTC (rev 2541)
@@ -388,7 +388,8 @@
                     generate_input($params);
                     break;
                   case 'email':
-                    $params['attributes'] = "type=email multiple";
+                    $params['type'] = 'email';
+                    $params['attributes'] = 'multiple';
                     generate_input($params);
                     break;
                   default:    

Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc        2012-10-30 09:04:46 UTC (rev 2540)
+++ mrbs/trunk/web/functions.inc        2012-10-30 10:56:16 UTC (rev 2541)
@@ -524,7 +524,7 @@
 //        'class'       A class (or array of classes) to give the element.  
Default NULL
 //        'disabled'    Whether the field should be disabled.  Default FALSE
 //        'mandatory'   Whether the field is a required field.  Default FALSE
-//        'attributes'  Additional attributes, allowing HTML5 attributes.  
Default NULL.
+//        'attributes'  Additional attributes not covered explicitly above.  
Default NULL.
 //                      Can be either a simple string or an array of 
attributes.
 //
 function generate_checkbox($params)
@@ -612,19 +612,22 @@
 //      OPTIONAL
 //        'label'       The text to be used for the field label.
 //        'value'       The value of the input.  Default ''
+//        'type'        The type of input, eg 'text', 'number', etc.  Default 
NULL
+//        'step'        The value of the 'step' attribute.  Default NULL
+//        'min'         The value of the 'min' attribute.  Default NULL
+//        'max'         The value of the 'max' attribute.  Default NULL
 //        'suffix'      A string that is displayed after the input field
 //        'disabled'    Whether the field should be disabled.  Default FALSE
 //        'mandatory'   Whether the field is a required field.  Default FALSE
 //        'maxlength'   The maximum length of input allowed.   Default NULL 
(no limit)
-//        'attributes'  Additional attributes, allowing HTML5 input types such 
as number and
-//                      email to be used.   Note that additional attributes 
such as min, etc.
-//                      can also be included in the string, eg 'type="number" 
min="1" step="1"'.
-//                      Default NULL.  Can be ither a simple string or an 
array of attributes.
+//        'attributes'  Additional attributes not covered explicitly above.  
Default NULL.
+//                      Can be either a simple string or an array of 
attributes.
 //
 function generate_simple_input($params)
 {
   // some sanity checking on params
-  foreach (array('label', 'name', 'value', 'disabled', 'mandatory', 
'maxlength', 'attributes', 'suffix') as $key)
+  foreach (array('label', 'name', 'value', 'type', 'step', 'disabled', 
'mandatory',
+                 'maxlength', 'attributes', 'suffix') as $key)
   {
     if (!isset($params[$key]))
     {
@@ -659,6 +662,11 @@
     $html .= "<label for=\"" . $params['name'] . "\">" . $params['label'] . 
"</label>\n";
   }
   $html .= "<input";
+  $html .= (isset($params['type'])) ? " type=\"" . $params['type'] . "\"" : "";
+  $html .= (isset($params['step'])) ? " step=\"" . $params['step'] . "\"" : "";
+  $html .= (isset($params['min'])) ? " min=\"" . $params['min'] . "\"" : "";
+  $html .= (isset($params['max'])) ? " max=\"" . $params['max'] . "\"" : "";
+  $html .= (isset($params['pattern'])) ? " pattern=\"" . 
htmlspecialchars($params['pattern']) . "\"" : "";
   $html .= (isset($params['attributes'])) ? " " . $params['attributes'] : "";
   $html .= " id=\"" . $params['name'] . "\" name=\"" . $params['name'] . "\"";
   $html .= ($params['disabled']) ? " disabled=\"disabled\"" : '';
@@ -666,9 +674,8 @@
   $html .= (isset($params['maxlength'])) ? " maxlength=\"" . 
$params['maxlength'] . "\"" : '';
   // Don't give an empty string if it's a number as that's not a valid 
floating point number
   // and will fail HTML5 validation
-  if (!(isset($params['attributes'])) ||
-      (strpos($params['attributes'], 'type="number"') === FALSE) ||
-      ($params['value'] != '') )
+  if (($params['value'] != '') ||
+      (isset($params['type']) && ($params['type'] != 'number')) )
   {
     $html .= " value=\"" . htmlspecialchars($params['value']) . "\"";
   }
@@ -707,7 +714,7 @@
 //        'attributes'  Additional attributes, allowing HTML5 input types such 
as number and
 //                      email to be used.   Note that additional attributes 
such as min, etc.
 //                      can also be included in the string, eg 'type="number" 
min="1" step="1"'.
-//                      Default NULL.  Can be ither a simple string or an 
array of attributes
+//                      Default NULL.  Can be either a simple string or an 
array of attributes
 function generate_input($params)
 {
   global $select_options, $datalist_options;
@@ -956,8 +963,8 @@
 //                        Default TRUE
 //        'mandatory'     Whether the field is a required field.  Default FALSE
 //        'multiple'      Whether multiple selections are allowed.  Default 
FALSE
-//        'attributes'    Can be used for passing other attributes.  Default 
NULL.
-//                        Can be either a simple string or an array of 
attributes
+//        'attributes'    Additional attributes not covered explicitly above.  
Default NULL.
+//                        Can be either a simple string or an array of 
attributes.
 //
 function generate_select($params)
 {
@@ -1073,8 +1080,8 @@
 //        'create_hidden' Boolean.  If TRUE hidden inputs are created if 
'disabled' is set
 //                        Default TRUE
 //        'mandatory'     Whether the field is a required field.  Default FALSE
-//        'attributes'    Can be used for passing other attributes.  Default 
NULL.
-//                        Can be either a simple string or an array of 
attributes
+//        'attributes'    Additional attributes not covered explicitly above.  
Default NULL.
+//                        Can be either a simple string or an array of 
attributes.
 //
 function generate_datalist($params)
 {
@@ -1186,7 +1193,7 @@
 //        'value'       The value of the input.  Default ''
 //        'disabled'    Whether the field should be disabled.  Default FALSE
 //        'mandatory'   Whether the field is a required field.  Default FALSE
-//        'attributes'  Additional attributes, allowing HTML5 attributes.  
Default NULL.
+//        'attributes'  Additional attributes not covered explicitly above.  
Default NULL.
 //                      Can be either a simple string or an array of 
attributes.
 //
 function generate_textarea($params)
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to