本文整理汇总了PHP中RGFormsModel::is_duplicate方法的典型用法代码示例。如果您正苦于以下问题:PHP RGFormsModel::is_duplicate方法的具体用法?PHP RGFormsModel::is_duplicate怎么用?PHP RGFormsModel::is_duplicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RGFormsModel
的用法示例。
在下文中一共展示了RGFormsModel::is_duplicate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public static function validate(&$form, $field_values, $page_number = 0, &$failed_validation_page = 0)
{
$form = apply_filters('gform_pre_validation', $form);
// validate form schedule
if (self::validate_form_schedule($form)) {
return false;
}
// validate entry limit
if (self::validate_entry_limit($form)) {
return false;
}
foreach ($form["fields"] as &$field) {
//If a page number is specified, only validates fields that are on current page
$field_in_other_page = $page_number > 0 && $field["pageNumber"] != $page_number;
//validate fields with "no duplicate" functionality when they are present on pages before the current page.
$validate_duplicate_feature = $field["noDuplicates"] && $page_number > 0 && $field["pageNumber"] <= $page_number;
if ($field_in_other_page && !$validate_duplicate_feature) {
continue;
}
//ignore validation if field is hidden or admin only
if (RGFormsModel::is_field_hidden($form, $field, $field_values) || $field["adminOnly"]) {
continue;
}
$value = RGFormsModel::get_field_value($field);
//display error message if field is marked as required and the submitted value is empty
if ($field["isRequired"] && self::is_empty($field, $form["id"])) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
} else {
if ($field["noDuplicates"] && RGFormsModel::is_duplicate($form["id"], $field, $value)) {
$field["failed_validation"] = true;
//set page number so the failed field displays if on multi-page form
$failed_validation_page = $field["pageNumber"];
$input_type = RGFormsModel::get_input_type($field);
switch ($input_type) {
case "date":
$default_message = __("This date has already been taken. Please select a new date.", "gravityforms");
break;
default:
$default_message = is_array($value) ? __("This field requires an unique entry and the values you entered have been already been used.", "gravityforms") : sprintf(__("This field requires an unique entry and '%s' has already been used", "gravityforms"), $value);
break;
}
$field["validation_message"] = apply_filters("gform_duplicate_message_{$form["id"]}", apply_filters("gform_duplicate_message", $default_message, $form), $form);
} else {
if (self::failed_state_validation($form["id"], $field, $value)) {
$field["failed_validation"] = true;
$field["validation_message"] = in_array($field["inputType"], array("singleproduct", "singleshipping", "hiddenproduct")) ? __("Please enter a valid value.", "gravityforms") : __("Invalid selection. Please select one of the available choices.", "gravityforms");
} else {
switch (RGFormsModel::get_input_type($field)) {
case "password":
$password = $_POST["input_" . $field["id"]];
$confirm = $_POST["input_" . $field["id"] . "_2"];
if ($password != $confirm) {
$field["failed_validation"] = true;
$field["validation_message"] = __("Your passwords do not match.", "gravityforms");
} else {
if (rgar($field, "passwordStrengthEnabled") && !rgempty("minPasswordStrength", $field) && !empty($password)) {
$strength = $_POST["input_" . $field["id"] . "_strength"];
$levels = array("short" => 1, "bad" => 2, "good" => 3, "strong" => 4);
if ($levels[$strength] < $levels[$field["minPasswordStrength"]]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Your password does not meet the required strength. <br/>Hint: To make it stronger, use upper and lower case letters, numbers and symbols like ! \" ? \$ % ^ & ).", "gravityforms") : $field["errorMessage"];
}
}
}
break;
case "name":
if ($field["isRequired"] && $field["nameFormat"] != "simple") {
$first = $_POST["input_" . $field["id"] . "_3"];
$last = $_POST["input_" . $field["id"] . "_6"];
if (empty($first) || empty($last)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter the first and last name.", "gravityforms") : $field["errorMessage"];
}
}
break;
case "address":
if ($field["isRequired"]) {
$street = $_POST["input_" . $field["id"] . "_1"];
$city = $_POST["input_" . $field["id"] . "_3"];
$state = $_POST["input_" . $field["id"] . "_4"];
$zip = $_POST["input_" . $field["id"] . "_5"];
$country = $_POST["input_" . $field["id"] . "_6"];
if (empty($street) || empty($city) || empty($zip) || empty($state) && !$field["hideState"] || empty($country) && !$field["hideCountry"]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a complete address.", "gravityforms") : $field["errorMessage"];
}
}
break;
case "creditcard":
$card_number = rgpost("input_" . $field["id"] . "_1");
$expiration_date = rgpost("input_" . $field["id"] . "_2");
$security_code = rgpost("input_" . $field["id"] . "_3");
if (rgar($field, "isRequired") && (empty($card_number) || empty($security_code) || empty($expiration_date[0]) || empty($expiration_date[1]))) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter your credit card information.", "gravityforms") : $field["errorMessage"];
} else {
if (!empty($card_number)) {
$card_type = GFCommon::get_card_type($card_number);
$security_code = rgpost("input_" . $field["id"] . "_3");
//.........这里部分代码省略.........
示例2: validate
public static function validate(&$form, $field_values, $page_number = 0, &$failed_validation_page = 0)
{
$form = gf_apply_filters(array('gform_pre_validation', $form['id']), $form);
// validate form schedule
if (self::validate_form_schedule($form)) {
return false;
}
// validate entry limit
if (self::validate_entry_limit($form)) {
return false;
}
// Prevent tampering with the submitted form
if (empty($_POST['is_submit_' . $form['id']])) {
return false;
}
$is_valid = true;
foreach ($form['fields'] as &$field) {
/* @var GF_Field $field */
//If a page number is specified, only validates fields that are on current page
$field_in_other_page = $page_number > 0 && $field->pageNumber != $page_number;
//validate fields with 'no duplicate' functionality when they are present on pages before the current page.
$validate_duplicate_feature = $field->noDuplicates && $page_number > 0 && $field->pageNumber <= $page_number;
if ($field_in_other_page && !$validate_duplicate_feature) {
continue;
}
// don't validate adminOnly fields.
if ($field->adminOnly) {
continue;
}
//ignore validation if field is hidden
if (RGFormsModel::is_field_hidden($form, $field, $field_values)) {
$field->is_field_hidden = true;
continue;
}
$value = RGFormsModel::get_field_value($field);
$input_type = RGFormsModel::get_input_type($field);
//display error message if field is marked as required and the submitted value is empty
if ($field->isRequired && self::is_empty($field, $form['id'])) {
$field->failed_validation = true;
$field->validation_message = empty($field->errorMessage) ? __('This field is required.', 'gravityforms') : $field->errorMessage;
} else {
if ($field->noDuplicates && RGFormsModel::is_duplicate($form['id'], $field, $value)) {
$field->failed_validation = true;
//set page number so the failed field displays if on multi-page form
$failed_validation_page = $field->pageNumber;
switch ($input_type) {
case 'date':
$default_message = __('This date has already been taken. Please select a new date.', 'gravityforms');
break;
default:
$default_message = is_array($value) ? __('This field requires a unique entry and the values you entered have been already been used.', 'gravityforms') : sprintf(__("This field requires a unique entry and '%s' has already been used", 'gravityforms'), $value);
break;
}
$field->validation_message = gf_apply_filters(array('gform_duplicate_message', $form['id']), $default_message, $form, $field, $value);
} else {
if (self::failed_state_validation($form['id'], $field, $value)) {
$field->failed_validation = true;
$field->validation_message = in_array($field->inputType, array('singleproduct', 'singleshipping', 'hiddenproduct')) ? __('Please enter a valid value.', 'gravityforms') : __('Invalid selection. Please select one of the available choices.', 'gravityforms');
} else {
$field->validate($value, $form);
}
}
}
$custom_validation_result = gf_apply_filters(array('gform_field_validation', $form['id'], $field->id), array('is_valid' => $field->failed_validation ? false : true, 'message' => $field->validation_message), $value, $form, $field);
$field->failed_validation = rgar($custom_validation_result, 'is_valid') ? false : true;
$field->validation_message = rgar($custom_validation_result, 'message');
if ($field->failed_validation) {
$is_valid = false;
}
}
$is_last_page = self::get_target_page($form, $page_number, $field_values) == '0';
if ($is_valid && $is_last_page && self::is_form_empty($form)) {
foreach ($form['fields'] as &$field) {
$field->failed_validation = true;
$field->validation_message = esc_html__('At least one field must be filled out', 'gravityforms');
$is_valid = false;
unset($field->is_field_hidden);
}
}
$validation_result = gf_apply_filters(array('gform_validation', $form['id']), array('is_valid' => $is_valid, 'form' => $form, 'failed_validation_page' => $failed_validation_page));
$is_valid = $validation_result['is_valid'];
$form = $validation_result['form'];
$failed_validation_page = $validation_result['failed_validation_page'];
return $is_valid;
}
示例3: validate
private function validate(&$form, $field_values)
{
$form = apply_filters('gform_pre_validation', $form);
foreach ($form["fields"] as &$field) {
/*
* Skip over the following fields as we aren't processing any of them
*/
$skip_field = false;
switch (RGFormsModel::get_input_type($field)) {
case "captcha":
case "html":
case "password":
case "product":
case "coupon":
case "quantity":
case "shipping":
case "donation":
case "total":
case "singleproduct":
case "hiddenproduct":
case "singleshipping":
case "creditcard":
case "page":
case "post_image":
case "fileupload":
//ignore certain fields
$skip_field = true;
break;
}
if (isset($field['productField']) && (int) $field['productField'] > 0 || $field['type'] == 'shipping') {
$skip_field = true;
}
/* ignore validation if field is hidden or admin only */
if (RGFormsModel::is_field_hidden($form, $field, $field_values) || isset($field['adminOnly']) && $field['adminOnly']) {
$skip_field = true;
}
/* ignore user-defined restricted fields or hidden fields */
if (in_array($field['id'], $this->atts['restricted_fields']) || in_array($field['id'], $this->atts['hidden_fields'])) {
$skip_field = true;
}
if ($skip_field) {
continue;
}
$value = RGFormsModel::get_field_value($field);
//display error message if field is marked as required and the submitted value is empty
if ($field["isRequired"] && GFFormDisplay::is_empty($field, $form["id"])) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
} else {
if ($field["noDuplicates"] && RGFormsModel::is_duplicate($form["id"], $field, $value)) {
$field["failed_validation"] = true;
$input_type = RGFormsModel::get_input_type($field);
switch ($input_type) {
case "date":
$default_message = __("This date has already been taken. Please select a new date.", "gravityforms");
break;
default:
$default_message = is_array($value) ? __("This field requires a unique entry and the values you entered have been already been used.", "gravityforms") : sprintf(__("This field requires a unique entry and '%s' has already been used", "gravityforms"), $value);
break;
}
$field["validation_message"] = apply_filters("gform_duplicate_message_{$form["id"]}", apply_filters("gform_duplicate_message", $default_message, $form, $field, $value), $form, $field, $value);
} else {
if (GFFormDisplay::failed_state_validation($form["id"], $field, $value)) {
$field["failed_validation"] = true;
$field["validation_message"] = in_array($field["inputType"], array("singleproduct", "singleshipping", "hiddenproduct")) ? __("Please enter a valid value.", "gravityforms") : __("Invalid selection. Please select one of the available choices.", "gravityforms");
} else {
switch (RGFormsModel::get_input_type($field)) {
case "name":
if ($field["isRequired"] && $field["nameFormat"] != "simple") {
$first = $_POST["input_" . $field["id"] . "_3"];
$last = $_POST["input_" . $field["id"] . "_6"];
if (empty($first) || empty($last)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter the first and last name.", "gravityforms") : $field["errorMessage"];
}
}
break;
case "address":
if ($field["isRequired"]) {
$street = $_POST["input_" . $field["id"] . "_1"];
$city = $_POST["input_" . $field["id"] . "_3"];
$state = $_POST["input_" . $field["id"] . "_4"];
$zip = $_POST["input_" . $field["id"] . "_5"];
$country = $_POST["input_" . $field["id"] . "_6"];
if (empty($street) || empty($city) || empty($zip) || empty($state) && !$field["hideState"] || empty($country) && !$field["hideCountry"]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a complete address.", "gravityforms") : $field["errorMessage"];
}
}
break;
case "email":
if (!rgblank($value) && !GFCommon::is_valid_email($value)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid email address.", "gravityforms") : $field["errorMessage"];
} else {
if (rgget("emailConfirmEnabled", $field) && !empty($value)) {
$confirm = rgpost("input_" . $field["id"] . "_2");
if ($confirm != $value) {
$field["failed_validation"] = true;
$field["validation_message"] = __("Your emails do not match.", "gravityforms");
//.........这里部分代码省略.........
示例4: validate
public static function validate(&$form, $field_values, $page_number = 0)
{
$is_valid = true;
foreach ($form["fields"] as &$field) {
//If a page number is specified, only validates fields that are on current page
if ($page_number > 0 && $field["pageNumber"] != $page_number) {
continue;
}
//ignore validation if field is hidden or admin only
if (RGFormsModel::is_field_hidden($form, $field, $field_values) || $field["adminOnly"]) {
continue;
}
$value = RGFormsModel::get_field_value($field);
//display error message if field is marked as required and the submitted value is empty
if ($field["isRequired"] && self::is_empty($field, $form["id"])) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
} else {
if ($field["noDuplicates"] && RGFormsModel::is_duplicate($form["id"], $field, $value)) {
$field["failed_validation"] = true;
$field["validation_message"] = is_array($value) ? apply_filters("gform_duplicate_message_{$form["id"]}", apply_filters("gform_duplicate_message", __("This field requires an unique entry and the values you entered have been already been used", "gravityforms"), $form), $form) : apply_filters("gform_duplicate_message_{$form["id"]}", apply_filters("gform_duplicate_message", sprintf(__("This field requires an unique entry and '%s' has already been used", "gravityforms"), $value), $form), $form);
$is_valid = false;
} else {
if (self::failed_state_validation($form["id"], $field, $value)) {
$field["failed_validation"] = true;
$field["validation_message"] = in_array($field["inputType"], array("singleproduct", "singleshipping")) ? __("Please enter a valid value.", "gravityforms") : __("Invalid selection. Please select one of the available choices.", "gravityforms");
$is_valid = false;
} else {
switch (RGFormsModel::get_input_type($field)) {
case "password":
$password = $_POST["input_" . $field["id"]];
$confirm = $_POST["input_" . $field["id"] . "_2"];
if ($password != $confirm) {
$field["failed_validation"] = true;
$field["validation_message"] = __("Your passwords do not match.", "gravityforms");
$is_valid = false;
} else {
if ($field["passwordStrengthEnabled"] && !empty($field["minPasswordStrength"]) && !empty($password)) {
$strength = $_POST["input_" . $field["id"] . "_strength"];
$levels = array("short" => 1, "bad" => 2, "good" => 3, "strong" => 4);
if ($levels[$strength] < $levels[$field["minPasswordStrength"]]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Your password does not meet the required strength. <br/>Hint: To make it stronger, use upper and lower case letters, numbers and symbols like ! \" ? \$ % ^ & ).", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
}
}
break;
case "name":
if ($field["isRequired"] && $field["nameFormat"] != "simple") {
$first = $_POST["input_" . $field["id"] . "_3"];
$last = $_POST["input_" . $field["id"] . "_6"];
if (empty($first) || empty($last)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter the first and last name.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
}
break;
case "address":
if ($field["isRequired"]) {
$street = $_POST["input_" . $field["id"] . "_1"];
$city = $_POST["input_" . $field["id"] . "_3"];
$state = $_POST["input_" . $field["id"] . "_4"];
$zip = $_POST["input_" . $field["id"] . "_5"];
$country = $_POST["input_" . $field["id"] . "_6"];
if (empty($street) || empty($city) || empty($zip) || empty($state) && !$field["hideState"] || empty($country) && !$field["hideCountry"]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a complete address.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
}
break;
case "email":
if (!empty($value) && !GFCommon::is_valid_email($value)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid email address.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
} else {
if (rgget("emailConfirmEnabled", $field) && !empty($value)) {
$confirm = rgpost("input_" . $field["id"] . "_2");
if ($confirm != $value) {
$field["failed_validation"] = true;
$field["validation_message"] = __("Your emails do not match.", "gravityforms");
$is_valid = false;
}
}
}
break;
case "donation":
case "price":
if (!class_exists("RGCurrency")) {
require_once "currency.php";
}
$donation = GFCommon::to_number($value);
if (!empty($value) && ($donation === false || $donation <= 0)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid donation", "gravityforms") : $field["errorMessage"];
$is_valid = false;
//.........这里部分代码省略.........
示例5: validate
public static function validate(&$form, $field_values)
{
$is_valid = true;
foreach ($form["fields"] as &$field) {
//ignore validation if field is hidden
if (RGFormsModel::is_field_hidden($form, $field, $field_values)) {
continue;
}
$value = RGFormsModel::get_field_value($field);
//display error message if field is marked as required and the submitted value is empty
if ($field["isRequired"] && self::is_empty($field)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a value.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
} else {
if ($field["noDuplicates"] && RGFormsModel::is_duplicate($form["id"], $field, $value)) {
$field["failed_validation"] = true;
$field["validation_message"] = is_array($value) ? __("This field requires an unique entry and the values you entered have been already been used", "gravityforms") : __(sprintf("This field requires an unique entry and '%s' has already been used", $value), "gravityforms");
$is_valid = false;
} else {
switch (RGFormsModel::get_input_type($field)) {
case "name":
if ($field["isRequired"] && $field["nameFormat"] != "simple") {
$first = $_POST["input_" . $field["id"] . "_3"];
$last = $_POST["input_" . $field["id"] . "_6"];
if (empty($first) || empty($last)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter the first and last name.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
}
break;
case "address":
if ($field["isRequired"]) {
$street = $_POST["input_" . $field["id"] . "_1"];
$city = $_POST["input_" . $field["id"] . "_3"];
$state = $_POST["input_" . $field["id"] . "_4"];
$zip = $_POST["input_" . $field["id"] . "_5"];
$country = $_POST["input_" . $field["id"] . "_6"];
if (empty($street) || empty($city) || empty($state) || empty($zip) || empty($country)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a complete address.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
}
break;
case "email":
if (!empty($value) && !GFCommon::is_valid_email($value)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid email address.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
break;
case "number":
if (trim($value) != '' && !self::validate_range($field, $value)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? GFCommon::get_range_message($field) : $field["errorMessage"];
$is_valid = false;
}
break;
case "phone":
$regex = '/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/';
if ($field["phoneFormat"] == "standard" && !empty($value) && !preg_match($regex, $value)) {
$field["failed_validation"] = true;
if (!empty($field["errorMessage"])) {
$field["validation_message"] = $field["errorMessage"];
}
$is_valid = false;
}
break;
case "date":
if (is_array($value) && empty($value[0])) {
$value = null;
}
if (!empty($value)) {
$format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"];
$date = GFCommon::parse_date($value, $format);
if (empty($date) || !checkdate($date["month"], $date["day"], $date["year"])) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __(sprintf("Please enter a valid date in the format (%s).", $format == "mdy" ? "mm/dd/yyyy" : "dd/mm/yyyy"), "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
}
break;
case "time":
//create variable values if time came in one field
if (!is_array($value) && !empty($value)) {
preg_match('/^(\\d*):(\\d*) (.*)$/', $value, $matches);
$value = array();
$value[0] = $matches[1];
$value[1] = $matches[2];
}
$hour = $value[0];
$minute = $value[1];
if (empty($hour) && empty($minute)) {
break;
}
$is_valid_format = is_numeric($hour) && is_numeric($minute);
if (!$is_valid_format || $hour <= 0 || $hour > 12 || $minute < 0 || $minute >= 60) {
$field["failed_validation"] = true;
//.........这里部分代码省略.........