本文整理汇总了PHP中Validation::add_error方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::add_error方法的具体用法?PHP Validation::add_error怎么用?PHP Validation::add_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::add_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _validate_icc_path
public function _validate_icc_path(Validation $post, $field)
{
if (!empty($post->{$field})) {
if (!@is_file($post->{$field})) {
$post->add_error($field, t("No ICC profile exists at the location <code>%icc_path</code>", array("icc_path" => $post->{$field})));
}
$dcraw = rawphoto_graphics::detect_dcraw();
if (version_compare($dcraw->version, "8.00", "<")) {
$post->add_error($field, t("Versions of <em>dcraw</em> before <code>8.00</code> do not support an ICC profile"));
}
}
}
示例2: layer_url_file_check
/**
* Performs validation checks on the layer url and layer file - Checks that at least
* one of them has been specified using the applicable validation rules
*
* @param Validation $array Validation object containing the field names to be checked
*/
public function layer_url_file_check(Validation $array)
{
// Ensure at least a layer URL or layer file has been specified
if (empty($array->layer_url) and empty($array->layer_file) and empty($array->layer_file_old)) {
$array->add_error('layer_url', 'atleast');
}
// Add validation rule for the layer URL if specified
if (!empty($array->layer_url) and (empty($array->layer_file) or empty($array->layer_file_old))) {
$array->add_rules('layer_url', 'url');
}
// Check if both the layer URL and the layer file have been specified
if (!empty($array->layer_url) and (!empty($array->layer_file_old) or !empty($array->layer_file))) {
$array->add_error('layer_url', 'both');
}
}
示例3: valid_name
/**
* Validate the item name. It can't conflict with other names, can't contain slashes or
* trailing periods.
*/
public function valid_name(Validation $v, $field)
{
$postage_band = ORM::factory("postage_band")->where("name", "=", $this->name)->find();
if ($postage_band->loaded() && $postage_band->id != $this->id) {
$v->add_error("name", "in_use");
}
}
示例4: action_edit_field
public function action_edit_field()
{
$field_id = $this->request->param('options');
xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content);
if (count($_POST) && isset($_POST['field_name'])) {
$post = new Validation($_POST);
$post->filter('trim');
$post->rule('Valid::not_empty', 'field_name');
if ($post->validate()) {
$post_values = $post->as_array();
if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) {
$post->add_error('field_name', 'User::field_name_available');
}
}
// Retry
if ($post->validate()) {
$post_values = $post->as_array();
User::update_field($field_id, $post_values['field_name']);
$this->add_message('Field ' . $post_values['field_name'] . ' updated');
$this->set_formdata(array('field_name' => $post_values['field_name']));
} else {
$this->add_error('Fix errors and try again');
$this->add_form_errors($post->errors());
$this->set_formdata(array_intersect_key($post->as_array(), $_POST));
}
} else {
$this->set_formdata(array('field_name' => User::get_data_field_name($field_id)));
}
}
示例5: file_check
/**
* Performs validation checks on the geometry file - Checks that at least
* one of them has been specified using the applicable validation rules
*
* @param Validation $array Validation object containing the field names to be checked
*/
public function file_check(Validation $array)
{
// Ensure at least a geometry URL or geometry file has been specified
if (empty($array->kml_file) and empty($array->kml_file_old)) {
$array->add_error('geometry_url', 'atleast');
}
}
示例6: valid_name
/**
* Validate the item name. It can't conflict with other names, can't contain slashes or
* trailing periods.
*/
public function valid_name(Validation $v, $field)
{
Kohana_Log::add("error", print_r("valid_name!", 1));
$product = ORM::factory("product")->where("name", "=", $this->name)->find();
if ($product->loaded() && $product->id != $this->id) {
$v->add_error("name", "in_use");
}
}
示例7: __dependents
/**
* If we want to delete the record, we need to check that no dependents exist.
*/
public function __dependents(Validation $array, $field)
{
if ($array['deleted'] == 'true') {
$record = ORM::factory('termlists_term', $array['id']);
if (count($record->children) != 0) {
$array->add_error($field, 'has_children');
}
}
}
示例8: _unique_email
public function _unique_email(Validation $array, $field)
{
// check the database for existing records
$email_exists = (bool) ORM::factory('launchingsoon_user')->where('email', $array[$field])->count_all();
if ($email_exists) {
// add error to validation object
$array->add_error($field, 'email_exists');
}
}
示例9: _dependents
/**
* If we want to delete the record, we need to check that no dependents exist.
*/
public function _dependents(Validation $array, $field)
{
if ($array['deleted'] == 'true') {
$record = ORM::factory('termlist', $array['id']);
if ($record->terms->count() != 0) {
$array->add_error($field, 'has_taxa');
}
}
}
示例10: _url_is_free
/**
* Look if email and password match with db
* @param Validation Validation object
* @param string field that all goes on
* @return boolean
*/
public function _url_is_free(Validation $array, $field)
{
// Questing database if url string
$url_is_free = $this->db->from(self::TN_PAGES)->where('url', $array[$field])->count_records();
if ($url_is_free != 0) {
$array->add_error($field, 'is_set');
} else {
return TRUE;
}
}
示例11: _exists
/**
* Callback - check if payment exists in db
* @return void
* @param integer id of payment method
*/
public function _exists(Validation $post)
{
// If add->rules validation found any errors, get me out of here!
if (array_key_exists('payment', $post->errors())) {
return;
}
// Check if shipping method exists
$data = $this->db->select('id')->from(self::TN_PAYMENT)->where('id', $post['payment'])->get();
if (count($data) <= 0) {
// Add a validation error, this will cause $post->validate() to return FALSE
$post->add_error('payment', 'required');
}
}
示例12: _admin_check_address
public function _admin_check_address(Validation $array, $input)
{
if ($array[$input] == '') {
return;
}
// Fetch the lat and lon via Gmap
list($lat, $lon) = Gmap::address_to_ll($array[$input]);
if ($lat === NULL or $lon === NULL) {
// Add an error
$array->add_error($input, 'address');
} else {
// Set the latitude and longitude
$_POST['lat'] = $lat;
$_POST['lon'] = $lon;
}
}
示例13: status_update
/**
* @method status_update
* @abstract Post status update to Twitter
* @author Josh Turmel
* @
* @return array
*/
public static function status_update($config)
{
$username = isset($config['username']) ? $config['username'] : '';
$password = isset($config['password']) ? $config['password'] : '';
$status = isset($config['status']) ? $config['status'] : '';
$v = new Validation(array('username' => $username, 'password' => $password, 'status' => $status));
// TODO: Add in the real requirements by Twitter, for now just required
$v->add_rules('username', 'required');
$v->add_rules('password', 'required');
$v->add_rules('status', 'required');
if ($v->validate() === false) {
return array('success' => false, 'errors' => $v->errors('twitter'));
}
$appended_message = Kohana::config('twitter.appended_message');
$max_length = self::status_length();
if (strlen($status) > $max_length) {
$status = substr($status, 0, $max_length - 2) . '...';
}
// Now add appended_message
$status = $status . $appended_message;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://twitter.com/statuses/update.json');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'status=' . $status);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
$output = curl_exec($ch);
curl_close($ch);
// Check for success or failure
if (empty($output)) {
$v = new Validation(array('twitter_response' => ''));
$v->add_error('twitter_response', 'connection_failed');
return array('success' => false, 'errors' => $v->errors('twitter'));
} else {
$output = json_decode($output);
if (isset($output->error) && $output->error == 'Could not authenticate you.') {
$v = new Validation(array('twitter_response' => ''));
$v->add_error('twitter_response', 'authentication_failed');
return array('success' => false, 'errors' => $v->errors('twitter'));
} else {
$output->success = true;
return $output;
}
}
}
示例14: email_exists_chk
/**
* Checks if email address is associated with an account.
* @param Validation $post $_POST variable with validation rules
*/
public function email_exists_chk(Validation $post)
{
$users = ORM::factory('user');
if (array_key_exists('resetemail', $post->errors())) {
return;
}
if (!$users->email_exists($post->resetemail)) {
$post->add_error('resetemail', 'invalid');
}
}
示例15: prevent_superadmin_modification
/**
* Ensures that only a superadmin can modify superadmin users, or upgrade a user to superadmin
* @note this assumes the currently logged-in user isn't a superadmin
*/
public static function prevent_superadmin_modification(Validation $post, $field)
{
if ($post[$field] == 'superadmin') {
$post->add_error($field, 'superadmin_modify');
}
}