本文整理汇总了PHP中validate::setRule方法的典型用法代码示例。如果您正苦于以下问题:PHP validate::setRule方法的具体用法?PHP validate::setRule怎么用?PHP validate::setRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类validate
的用法示例。
在下文中一共展示了validate::setRule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _saveNotifications
protected function _saveNotifications($userID, $settings)
{
// Check if demo mode is enabled
if (input::demo()) {
return false;
}
// Validate form fields
foreach ($settings as $keyword => $setting) {
if (isset($setting['rules'])) {
validate::setRule($keyword, $setting['name'], $setting['rules']);
}
}
// Validate fields
if (!validate::run()) {
return false;
}
// Set notifications settings
$insert = $delete = array();
foreach ($settings as $keyword => $setting) {
$data = input::post($keyword);
if (isset($data['insert']) && isset($data['delete'])) {
$insert = array_merge($insert, $data['insert']);
$delete = array_merge($delete, $data['delete']);
}
}
// Save notifications
if ($insert && !$this->users_model->saveConfig($userID, $insert) || $delete && !$this->users_model->deleteConfig($userID, $delete)) {
view::setError(__('save_error', 'system'));
return false;
}
// Success
view::setInfo(__('notifications_saved', 'users_notifications'));
router::redirect('cp/users/notifications/' . $userID);
}
示例2: _saveField
protected function _saveField($plugin, $table, $categoryID, $fieldID, $fieldOld, $configs, $hidden)
{
// Check if demo mode is enabled
if (input::demo()) {
return false;
}
// Rules array
$rules = array();
// Data array
$inputData = array('keyword', 'type', 'style', 'class', 'required', 'system', 'multilang');
// Name
foreach (config::item('languages', 'core', 'keywords') as $languageID => $lang) {
$rules['name_' . $lang] = array('label' => __('name', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required', 'max_length' => 255));
$rules['vname_' . $lang] = array('label' => __('name_view', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
$rules['sname_' . $lang] = array('label' => __('name_search', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
$rules['validate_error_' . $lang] = array('label' => __('validate_error', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
$inputData[] = 'name_' . $lang;
$inputData[] = 'vname_' . $lang;
$inputData[] = 'sname_' . $lang;
$inputData[] = 'validate_error_' . $lang;
}
// Keyword
$rules['keyword'] = array('label' => __('keyword', 'system'), 'rules' => array('trim', 'required', 'alpha_dash', 'max_length' => 128, 'callback__is_unique_keyword' => array($plugin, $categoryID, $fieldID), 'callback__is_system_field' => array($fieldID ? $fieldOld['keyword'] : '', $fieldID ? $fieldOld['system'] : '')));
// Type
$rules['type'] = array('label' => __('field_type', 'system_fields'), 'rules' => array('required', 'callback__is_system_field' => array($fieldID ? $fieldOld['type'] : '', $fieldID ? $fieldOld['system'] : '')));
// Style value
$rules['style'] = array('label' => __('style', 'system_fields'), 'rules' => array('trim'));
// Class value
$rules['class'] = array('label' => __('class', 'system_fields'), 'rules' => array('trim'));
// Required
$rules['required'] = array('label' => __('required', 'system_fields'), 'rules' => array('intval'));
// Regular expression
$rules['validate'] = array('label' => __('validate', 'system_fields'), 'rules' => array('trim'));
$inputData[] = 'validate';
// Configuration array
$inputConfig = array();
foreach (array('custom', input::post('type')) as $conf) {
if (isset($configs[$conf])) {
foreach ($configs[$conf] as $option) {
$rules['config_' . $conf . '_' . $option['keyword']] = array('label' => utf8::strtolower($option['label']), 'rules' => isset($option['rules']) ? $option['rules'] : array());
$inputConfig[$option['keyword']] = 'config_' . $conf . '_' . $option['keyword'];
}
}
}
// Add items rules
$items = array();
$oldItems = $fieldID ? $fieldOld['items'] : array();
if ($this->fields_model->isMultiValue(input::post('type'))) {
$itemsPost = input::post('items');
$sitemsPost = input::post('sitems');
foreach (config::item('languages', 'core', 'keywords') as $languageID => $lang) {
$orderID = 1;
if (isset($itemsPost[$lang]) && is_array($itemsPost[$lang])) {
foreach ($itemsPost[$lang] as $itemID => $itemName) {
// Trim name
$itemName = utf8::trim($itemName);
// Assign item data
$items[$itemID]['order_id'] = $orderID;
$items[$itemID]['name_' . $lang] = $itemName;
$items[$itemID]['sname_' . $lang] = $sitemsPost[$lang][$itemID];
$orderID++;
// Add rule
$rules['items[' . $lang . '][' . $itemID . ']'] = array();
if ($itemName == '') {
validate::setRule('items', '', '');
validate::setFieldError('items', __('empty_item', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''));
}
}
}
}
if (!$items) {
validate::setRule('items', '', '');
validate::setFieldError('items', __('no_items', 'system_fields'));
}
view::assign(array('field' => array('items' => $items)));
}
// Assign rules
validate::setRules($rules);
// Validate fields
if (!validate::run()) {
return false;
}
// Get post data
$fieldData = input::post($inputData);
// Default data
$fieldData['system'] = isset($hidden['system']) ? $hidden['system'] : 0;
$fieldData['multilang'] = isset($hidden['multilang']) ? $hidden['multilang'] : 0;
// Get config data
$fieldData['config'] = array();
foreach ($inputConfig as $key => $val) {
$fieldData['config'][$key] = input::post($val);
}
// Set additional config data
$fieldData['config']['html'] = input::post('html') ? 1 : 0;
$fieldData['config']['in_search'] = input::post('in_search') ? 1 : 0;
$fieldData['config']['in_search_advanced'] = input::post('in_search_advanced') ? 1 : 0;
if ($fieldData['config']['in_search'] || $fieldData['config']['in_search_advanced']) {
$fieldData['config']['search_options'] = input::post('search_options') ? input::post('search_options') : '';
}
if (input::post('type') == 'checkbox' || input::post('search_options') == 'multiple') {
//.........这里部分代码省略.........