本文整理汇总了PHP中CI_Form_validation::_execute方法的典型用法代码示例。如果您正苦于以下问题:PHP CI_Form_validation::_execute方法的具体用法?PHP CI_Form_validation::_execute怎么用?PHP CI_Form_validation::_execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CI_Form_validation
的用法示例。
在下文中一共展示了CI_Form_validation::_execute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _execute
/**
*Custom Form Validation Error Messages
*http://ajmm.org/2011/07/custom-form-validation-error-messages-in-codeigniter-2/
*/
public function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
// Execute the parent method from CI_Form_validation.
parent::_execute($row, $rules, $postdata, $cycles);
// Override any error messages for the current field.
if (isset($this->_error_array[$row['field']]) && isset($this->_custom_field_errors[$row['field']])) {
$message = str_replace('%s', !empty($row['label']) ? $row['label'] : $row['field'], $this->_custom_field_errors[$row['field']]);
$this->_error_array[$row['field']] = $message;
$this->_field_data[$row['field']]['error'] = $message;
}
}
示例2: _execute
public function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
if (!is_array($postdata) && strlen($postdata) == 0 || is_array($postdata) && empty($postdata)) {
$postdata = NULL;
}
return parent::_execute($row, $rules, $postdata, $cycles);
}
示例3: elseif
function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
log_message('DEBUG', 'called MY_form_validation::_execute ' . $row['field']);
//changed based on
//http://codeigniter.com/forums/viewthread/123816/P10/#619868
if (isset($_FILES[$row['field']])) {
// it is a file so process as a file
log_message('DEBUG', 'processing as a file');
$postdata = $_FILES[$row['field']];
//required bug
//if some stupid like me never remember that it's file_required and not required
//this will save a lot of var_dumping time.
if (in_array('required', $rules)) {
$rules[array_search('required', $rules)] = 'file_required';
}
//before doing anything check for errors
if ($postdata['error'] !== UPLOAD_ERR_OK) {
//If the error it's 4 (ERR_NO_FILE) and the file required it's deactivated don't call an error
if ($postdata['error'] != UPLOAD_ERR_NO_FILE) {
$this->_error_array[$row['field']] = $this->file_upload_error_message($row['label'], $postdata['error']);
$this->_field_data[$row['field']]['error'] = $this->file_upload_error_message($row['label'], $postdata['error']);
return FALSE;
} elseif ($postdata['error'] == UPLOAD_ERR_NO_FILE and in_array('file_required', $rules)) {
$this->_error_array[$row['field']] = $this->file_upload_error_message($row['label'], $postdata['error']);
$this->_field_data[$row['field']]['error'] = $this->file_upload_error_message($row['label'], $postdata['error']);
return FALSE;
}
}
$_in_array = FALSE;
// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
if (!in_array('file_required', $rules) and $postdata['size'] == 0) {
// Before we bail out, does the rule contain a callback?
if (preg_match("/(callback_\\w+)/", implode(' ', $rules), $match)) {
$callback = TRUE;
$rules = array('1' => $match[1]);
} else {
return;
}
}
foreach ($rules as $rule) {
/// COPIED FROM the original class
// Is the rule a callback?
$callback = $callable = FALSE;
if (is_string($rule)) {
if (strpos($rule, 'callback_') === 0) {
$rule = substr($rule, 9);
$callback = TRUE;
}
} elseif (is_callable($rule)) {
$callable = TRUE;
}
// Strip the parameter (if exists) from the rule
// Rules can contain a parameter: max_length[5]
$param = FALSE;
if (!$callable && preg_match('/(.*?)\\[(.*)\\]/', $rule, $match)) {
$rule = $match[1];
$param = $match[2];
}
// Call the function that corresponds to the rule
if ($callback or $callable) {
if ($callback) {
if (!method_exists($this->CI, $rule)) {
log_message('debug', 'Unable to find callback validation rule: ' . $rule);
$result = FALSE;
} else {
// Run the function and grab the result
$result = $this->CI->{$rule}($postdata, $param);
}
} else {
$result = is_array($rule) ? $rule[0]->{$rule[1]}($postdata, $param) : $rule($postdata, $param);
}
// Re-assign the result to the master data array
if ($_in_array == TRUE) {
$this->_field_data[$row['field']]['postdata'][$cycles] = is_bool($result) ? $postdata : $result;
} else {
$this->_field_data[$row['field']]['postdata'] = is_bool($result) ? $postdata : $result;
}
// If the field isn't required and we just processed a callback we'll move on...
if (!in_array('file_required', $rules, TRUE) and $result !== FALSE) {
return;
}
} elseif (!method_exists($this, $rule)) {
// If our own wrapper function doesn't exist we see if a native PHP function does.
// Users can use any native PHP function call that has one param.
if (function_exists($rule)) {
// Native PHP functions issue warnings if you pass them more parameters than they use
$result = $param !== FALSE ? $rule($postdata, $param) : $rule($postdata);
if ($_in_array === TRUE) {
$this->_field_data[$row['field']]['postdata'][$cycles] = is_bool($result) ? $postdata : $result;
} else {
$this->_field_data[$row['field']]['postdata'] = is_bool($result) ? $postdata : $result;
}
} else {
log_message('debug', 'Unable to find validation rule: ' . $rule);
$result = FALSE;
}
} else {
$result = $this->{$rule}($postdata, $param);
if ($_in_array === TRUE) {
//.........这里部分代码省略.........
示例4: elseif
function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
log_message('DEBUG', 'called Brightery_form_validation::_execute ' . $row['field']);
if (isset($_FILES[$row['field']])) {
// it is a file so process as a file
log_message('DEBUG', 'processing as a file');
$postdata = $_FILES[$row['field']];
//required bug
//if some stupid like me never remember that it's file_required and not required
//this will save a lot of var_dumping time.
if (in_array('required', $rules)) {
$rules[array_search('required', $rules)] = 'file_required';
}
//before doing anything check for errors
if ($postdata['error'] !== UPLOAD_ERR_OK) {
//If the error it's 4 (ERR_NO_FILE) and the file required it's deactivated don't call an error
if ($postdata['error'] != UPLOAD_ERR_NO_FILE) {
$this->_error_array[$row['field']] = $this->file_upload_error_message($row['label'], $postdata['error']);
return FALSE;
} elseif ($postdata['error'] == UPLOAD_ERR_NO_FILE and in_array('file_required', $rules)) {
$this->_error_array[$row['field']] = $this->file_upload_error_message($row['label'], $postdata['error']);
return FALSE;
}
}
$_in_array = FALSE;
// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
if (!in_array('file_required', $rules) and $postdata['size'] == 0) {
// Before we bail out, does the rule contain a callback?
if (preg_match("/(callback_\\w+)/", implode(' ', $rules), $match)) {
$callback = TRUE;
$rules = array('1' => $match[1]);
} else {
return;
}
}
foreach ($rules as $rule) {
/// COPIED FROM the original class
// Is the rule a callback?
$callback = FALSE;
if (substr($rule, 0, 9) == 'callback_') {
$rule = substr($rule, 9);
$callback = TRUE;
}
// Strip the parameter (if exists) from the rule
// Rules can contain a parameter: max_length[5]
$param = FALSE;
if (preg_match("/(.*?)\\[(.*?)\\]/", $rule, $match)) {
$rule = $match[1];
$param = $match[2];
}
// Call the function that corresponds to the rule
if ($callback === TRUE) {
if (!method_exists($this->CI, $rule)) {
continue;
}
// Run the function and grab the result
$result = $this->CI->{$rule}($postdata, $param);
// Re-assign the result to the master data array
if ($_in_array == TRUE) {
$this->_field_data[$row['field']]['postdata'][$cycles] = is_bool($result) ? $postdata : $result;
} else {
$this->_field_data[$row['field']]['postdata'] = is_bool($result) ? $postdata : $result;
}
// If the field isn't required and we just processed a callback we'll move on...
if (!in_array('file_required', $rules, TRUE) and $result !== FALSE) {
return;
}
} else {
if (!method_exists($this, $rule)) {
// If our own wrapper function doesn't exist we see if a native PHP function does.
// Users can use any native PHP function call that has one param.
if (function_exists($rule)) {
$result = $rule($postdata);
if ($_in_array == TRUE) {
$this->_field_data[$row['field']]['postdata'][$cycles] = is_bool($result) ? $postdata : $result;
} else {
$this->_field_data[$row['field']]['postdata'] = is_bool($result) ? $postdata : $result;
}
}
continue;
}
$result = $this->{$rule}($postdata, $param);
if ($_in_array == TRUE) {
$this->_field_data[$row['field']]['postdata'][$cycles] = is_bool($result) ? $postdata : $result;
} else {
$this->_field_data[$row['field']]['postdata'] = is_bool($result) ? $postdata : $result;
}
}
//this line needs testing !!!!!!!!!!!!! not sure if it will work
//it basically puts back the tested values back into $_FILES
//$_FILES[$row['field']] = $this->_field_data[$row['field']]['postdata'];
// Did the rule test negatively? If so, grab the error.
if ($result === FALSE) {
if (!isset($this->_error_messages[$rule])) {
if (FALSE === ($line = $this->CI->lang->line($rule))) {
$line = 'Unable to access an error message corresponding to your field name.';
}
} else {
$line = $this->_error_messages[$rule];
//.........这里部分代码省略.........