Skip to content
Browse files

added HTML5 "required" attribute. This lightens server load as checks…

… are performed inside browser. XHTML compatible notation used for greater compatibility.

see http://developers.whatwg.org/common-input-element-attributes.html#attr-input-required
  • Loading branch information...
1 parent fae6e46 commit 3e8e72d1269b8c24e7ac343e05b31486326076d8 @patrickheck committed Mar 22, 2012
Showing with 10 additions and 9 deletions.
  1. +10 −9 web/concrete/blocks/form/controller.php
View
19 web/concrete/blocks/form/controller.php
@@ -658,7 +658,7 @@ function loadSurvey( $qsID, $showEdit=false, $bID=0, $hideQIDs=array(), $showPen
$requiredSymbol=($questionRow['required'])?'&nbsp;<span class="required">*</span>':'';
echo '<tr>
<td valign="top" class="question"><label for="Question'.intval($questionRow['msqID']).'">'.$questionRow['question'].''.$requiredSymbol.'</label></td>
- <td valign="top">'.$this->loadInputType($questionRow,showEdit).'</td>
+ <td valign="top">'.$this->loadInputType($questionRow,showEdit,$questionRow['required']).'</td>
</tr>';
//}
}
@@ -709,7 +709,8 @@ function loadSurvey( $qsID, $showEdit=false, $bID=0, $hideQIDs=array(), $showPen
}
}
- function loadInputType($questionData,$showEdit){
+ function loadInputType($questionData,$showEdit,$required=false){
+ $required = $required?'required="required"':'';
$options=explode('%%',$questionData['options']);
$msqID=intval($questionData['msqID']);
switch($questionData['inputType']){
@@ -747,30 +748,30 @@ function loadInputType($questionData,$showEdit){
foreach($options as $option){
if(strlen(trim($option))==0) continue;
$checked=($_REQUEST['Question'.$msqID]==trim($option))?'checked':'';
- $html.= '<div class="radioPair"><input name="Question'.$msqID.'" type="radio" value="'.trim($option).'" '.$checked.' />&nbsp;'.$option.'</div>';
+ $html.= '<div class="radioPair"><input name="Question'.$msqID.'" type="radio" value="'.trim($option).'" '.$checked.' '.$required.' />&nbsp;'.$option.'</div>';
}
return $html;
case 'fileupload':
- $html='<input type="file" name="Question'.$msqID.'" id="Question'.$msqID.'" />';
+ $html='<input type="file" name="Question'.$msqID.'" id="Question'.$msqID.'" '.$required.' />';
return $html;
case 'text':
$val=($_REQUEST['Question'.$msqID])?Loader::helper('text')->entities($_REQUEST['Question'.$msqID]):'';
- return '<textarea name="Question'.$msqID.'" id="Question'.$msqID.'" cols="'.$questionData['width'].'" rows="'.$questionData['height'].'" style="width:95%">'.$val.'</textarea>';
+ return '<textarea name="Question'.$msqID.'" id="Question'.$msqID.'" cols="'.$questionData['width'].'" rows="'.$questionData['height'].'" style="width:95%" '.$required.'>'.$val.'</textarea>';
case 'url':
$val=($_REQUEST['Question'.$msqID])?$_REQUEST['Question'.$msqID]:'';
- return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" type="url" value="'.stripslashes(htmlspecialchars($val)).'" />';
+ return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" type="url" value="'.stripslashes(htmlspecialchars($val)).'" '.$required.' />';
case 'telephone':
$val=($_REQUEST['Question'.$msqID])?$_REQUEST['Question'.$msqID]:'';
- return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" type="tel" value="'.stripslashes(htmlspecialchars($val)).'" />';
+ return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" type="tel" value="'.stripslashes(htmlspecialchars($val)).'" '.$required.' />';
case 'email':
$val=($_REQUEST['Question'.$msqID])?$_REQUEST['Question'.$msqID]:'';
- return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" type="email" value="'.stripslashes(htmlspecialchars($val)).'" />';
+ return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" type="email" value="'.stripslashes(htmlspecialchars($val)).'" '.$required.' />';
case 'field':
default:
$val=($_REQUEST['Question'.$msqID])?$_REQUEST['Question'.$msqID]:'';
- return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" type="text" value="'.stripslashes(htmlspecialchars($val)).'" />';
+ return '<input name="Question'.$msqID.'" id="Question'.$msqID.'" type="text" value="'.stripslashes(htmlspecialchars($val)).'" '.$required.' />';
}
}

0 comments on commit 3e8e72d

Please sign in to comment.
Something went wrong with that request. Please try again.