本文整理汇总了PHP中FormElement::setValidationRules方法的典型用法代码示例。如果您正苦于以下问题:PHP FormElement::setValidationRules方法的具体用法?PHP FormElement::setValidationRules怎么用?PHP FormElement::setValidationRules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormElement
的用法示例。
在下文中一共展示了FormElement::setValidationRules方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createElementObject
//.........这里部分代码省略.........
// Checkbox
// Checkbox
case 'checkbox':
$label = false;
if (isset($fieldDetails['extralabel'])) {
$label = $fieldDetails['extralabel'];
}
$elem->setTypeAsCheckbox($label);
break;
// Checkbox List
// Checkbox List
case 'checkboxlist':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsCheckboxList($options);
break;
// Merged Fields - process each sub element
// Merged Fields - process each sub element
case 'merge':
$elementList = array();
if (!empty($fieldDetails['merge'])) {
foreach ($fieldDetails['merge'] as $fieldName => $fieldDetails) {
$elementList[] = $this->createElementObject($fieldName, $fieldDetails);
}
}
$elem->setTypeAsMergedElements($elementList);
break;
// File upload
// File upload
case 'uploadfile':
$elem->setTypeAsUploadFile($this->formObj->getArrayValue($fieldDetails, 'show_existing'), $this->formObj->getArrayValue($fieldDetails, 'valid_if_value'));
break;
// Custom HTML
// Custom HTML
case 'custom':
$elem->setTypeAsCustom($this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Hidden field
// Hidden field
case 'hidden':
$elem->setTypeAsHidden();
break;
// Section break
// Section break
case 'break':
$this->formObj->addBreak($fieldName, $this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Text box
// Text box
default:
break;
}
// Add optional fields
if ($type != 'break') {
// Element description
if ($desc = $this->formObj->getArrayValue($fieldDetails, 'desc')) {
$elem->description = $desc;
}
// Extra CSS
if ($cssclass = $this->formObj->getArrayValue($fieldDetails, 'cssclass')) {
$elem->cssclass = $cssclass;
}
// Add extra HTML if provided.
$extraHTML = $this->formObj->getArrayValue($fieldDetails, 'extrahtml');
if ($extraHTML) {
$elem->afterFormElementHTML = $extraHTML;
}
// Add custom error message if there is one
$elem->errorMessage = $this->formObj->getArrayValue($fieldDetails, 'errormsg');
// Validation rules
if (isset($fieldDetails['validate']) && is_array($fieldDetails['validate'])) {
// Is it a custom function? If so, get the function name.
if ($this->formObj->getArrayValue($fieldDetails['validate'], 'type') == 'function') {
$elem->validationFn = $this->formObj->getArrayValue($fieldDetails['validate'], 'fname');
$elem->errorMessage = $this->formObj->getArrayValue($fieldDetails['validate'], 'error');
} else {
$elem->setValidationRules($fieldDetails['validate']);
}
}
// See if there are any suffix items? If so, parse them.
// See wiki for documentation on how to structure this.
if (!empty($fieldDetails['suffix_subitems'])) {
$suffixItems = array();
// suffix_subitems contains a list of 'position' => array(fieldName => fieldDetails)
foreach ($fieldDetails['suffix_subitems'] as $position => $elementDetails) {
$suffixItems[$position] = array();
// Need to process each field now we know the position.
foreach ($elementDetails as $fieldName => $fieldDetails) {
// Add the position of this item (in order), with the object for this element.
$suffixItems[$position][] = $this->createElementObject($fieldName, $fieldDetails);
}
}
// Update the form element with the subitems
$elem->setSuffixItems($suffixItems);
}
}
return $elem;
}
示例2: createElementObject
//.........这里部分代码省略.........
if ($rows == 0) {
$rows = 5;
}
$elem->setTypeAsTextArea($rows, 70);
break;
// Select/Dropdown
// Select/Dropdown
case 'select':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsComboBox($options);
break;
// Radio Buttons
// Radio Buttons
case 'radio':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsRadioButtons($options);
break;
// Checkbox
// Checkbox
case 'checkbox':
$label = false;
if (isset($fieldDetails['extralabel'])) {
$label = $fieldDetails['extralabel'];
}
$elem->setTypeAsCheckbox($label);
break;
// Checkbox List
// Checkbox List
case 'checkboxlist':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsCheckboxList($options);
break;
// Merged Fields - process each sub element
// Merged Fields - process each sub element
case 'merge':
$elementList = array();
if (!empty($fieldDetails['merge'])) {
foreach ($fieldDetails['merge'] as $fieldName => $fieldDetails) {
$elementList[] = $this->createElementObject($fieldName, $fieldDetails);
}
}
$elem->setTypeAsMergedElements($elementList);
break;
// Custom HTML
// Custom HTML
case 'custom':
$elem->setTypeAsCustom($this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Hidden field
// Hidden field
case 'hidden':
$elem->setTypeAsHidden();
break;
// Section break
// Section break
case 'break':
$this->formObj->addBreak($fieldName, $this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Text box
// Text box
default:
break;
}
// Add optional fields
if ($type != 'break') {
// Element description
if ($desc = $this->formObj->getArrayValue($fieldDetails, 'desc')) {
$elem->description = $desc;
}
// Extra CSS
if ($cssclass = $this->formObj->getArrayValue($fieldDetails, 'cssclass')) {
$elem->cssclass = $cssclass;
}
// Add extra HTML if provided.
$extraHTML = $this->formObj->getArrayValue($fieldDetails, 'extrahtml');
if ($extraHTML) {
$elem->afterFormElementHTML = $extraHTML;
}
// Validation rules
if (isset($fieldDetails['validate']) && is_array($fieldDetails['validate'])) {
// Is it a custom function? If so, get the function name.
if ($this->formObj->getArrayValue($fieldDetails['validate'], 'type') == 'function') {
$elem->validationFn = $this->formObj->getArrayValue($fieldDetails['validate'], 'fname');
$elem->errorMessage = $this->formObj->getArrayValue($fieldDetails['validate'], 'error');
} else {
$elem->setValidationRules($fieldDetails['validate']);
}
}
}
return $elem;
}