本文整理汇总了PHP中GFCommon::is_valid_url方法的典型用法代码示例。如果您正苦于以下问题:PHP GFCommon::is_valid_url方法的具体用法?PHP GFCommon::is_valid_url怎么用?PHP GFCommon::is_valid_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GFCommon
的用法示例。
在下文中一共展示了GFCommon::is_valid_url方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
//.........这里部分代码省略.........
$field["validation_message"] = empty($field["errorMessage"]) ? $message : $field["errorMessage"];
}
}
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);
$min_hour = rgar($field, "timeFormat") == "24" ? 0 : 1;
$max_hour = rgar($field, "timeFormat") == "24" ? 23 : 12;
if (!$is_valid_format || $hour < $min_hour || $hour > $max_hour || $minute < 0 || $minute >= 60) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid time.", "gravityforms") : $field["errorMessage"];
}
break;
case "website":
if (empty($value) || $value == "http://") {
$value = "";
if ($field["isRequired"]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
}
}
if (!empty($value) && !GFCommon::is_valid_url($value)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid Website URL (i.e. http://www.gravityforms.com).", "gravityforms") : $field["errorMessage"];
}
break;
case "captcha":
switch ($field["captchaType"]) {
case "simple_captcha":
if (class_exists("ReallySimpleCaptcha")) {
$prefix = $_POST["input_captcha_prefix_{$field["id"]}"];
$captcha_obj = GFCommon::get_simple_captcha();
if (!$captcha_obj->check($prefix, str_replace(" ", "", $value))) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("The CAPTCHA wasn't entered correctly. Go back and try it again.", "gravityforms") : $field["errorMessage"];
}
//removes old files in captcha folder (older than 1 hour);
$captcha_obj->cleanup();
}
break;
case "math":
$prefixes = explode(",", $_POST["input_captcha_prefix_{$field["id"]}"]);
$captcha_obj = GFCommon::get_simple_captcha();
//finding first number
$first = 0;
for ($first = 0; $first < 10; $first++) {
if ($captcha_obj->check($prefixes[0], $first)) {
break;
}
}
//finding second number
$second = 0;
for ($second = 0; $second < 10; $second++) {
if ($captcha_obj->check($prefixes[2], $second)) {
示例2: get_lead_field_display
public static function get_lead_field_display($field, $value, $currency = "", $use_text = false, $format = "html", $media = "screen")
{
if ($field['type'] == 'post_category') {
$value = self::prepare_post_category_value($value, $field);
}
switch (RGFormsModel::get_input_type($field)) {
case "name":
if (is_array($value)) {
$prefix = trim(rgget($field["id"] . ".2", $value));
$first = trim(rgget($field["id"] . ".3", $value));
$last = trim(rgget($field["id"] . ".6", $value));
$suffix = trim(rgget($field["id"] . ".8", $value));
$name = $prefix;
$name .= !empty($name) && !empty($first) ? " {$first}" : $first;
$name .= !empty($name) && !empty($last) ? " {$last}" : $last;
$name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix;
return $name;
} else {
return $value;
}
break;
case "creditcard":
if (is_array($value)) {
$card_number = trim(rgget($field["id"] . ".1", $value));
$card_type = trim(rgget($field["id"] . ".4", $value));
$separator = $format == "html" ? "<br/>" : "\n";
return empty($card_number) ? "" : $card_type . $separator . $card_number;
} else {
return "";
}
break;
case "address":
if (is_array($value)) {
$street_value = trim(rgget($field["id"] . ".1", $value));
$street2_value = trim(rgget($field["id"] . ".2", $value));
$city_value = trim(rgget($field["id"] . ".3", $value));
$state_value = trim(rgget($field["id"] . ".4", $value));
$zip_value = trim(rgget($field["id"] . ".5", $value));
$country_value = trim(rgget($field["id"] . ".6", $value));
$line_break = $format == "html" ? "<br />" : "\n";
$address_display_format = apply_filters("gform_address_display_format", "default");
if ($address_display_format == "zip_before_city") {
/*
Sample:
3333 Some Street
suite 16
2344 City, State
Country
*/
$addr_ary = array();
$addr_ary[] = $street_value;
if (!empty($street2_value)) {
$addr_ary[] = $street2_value;
}
$zip_line = trim($zip_value . " " . $city_value);
$zip_line .= !empty($zip_line) && !empty($state_value) ? ", {$state_value}" : $state_value;
$zip_line = trim($zip_line);
if (!empty($zip_line)) {
$addr_ary[] = $zip_line;
}
if (!empty($country_value)) {
$addr_ary[] = $country_value;
}
$address = implode("<br />", $addr_ary);
} else {
$address = $street_value;
$address .= !empty($address) && !empty($street2_value) ? $line_break . $street2_value : $street2_value;
$address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? $line_break . $city_value : $city_value;
$address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", {$state_value}" : $state_value;
$address .= !empty($address) && !empty($zip_value) ? " {$zip_value}" : $zip_value;
$address .= !empty($address) && !empty($country_value) ? $line_break . $country_value : $country_value;
}
//adding map link
if (!empty($address) && $format == "html") {
$address_qs = str_replace($line_break, " ", $address);
//replacing <br/> and \n with spaces
$address_qs = urlencode($address_qs);
$address .= "<br/><a href='http://maps.google.com/maps?q={$address_qs}' target='_blank' class='map-it-link'>Map It</a>";
}
return $address;
} else {
return "";
}
break;
case "email":
return GFCommon::is_valid_email($value) && $format == "html" ? "<a href='mailto:{$value}'>{$value}</a>" : $value;
break;
case "website":
return GFCommon::is_valid_url($value) && $format == "html" ? "<a href='{$value}' target='_blank'>{$value}</a>" : $value;
break;
case "checkbox":
if (is_array($value)) {
$items = '';
foreach ($value as $key => $item) {
if (!empty($item)) {
switch ($format) {
case "text":
$items .= GFCommon::selection_display($item, $field, $currency, $use_text) . ", ";
break;
default:
//.........这里部分代码省略.........
示例3: handle_confirmation_edit_submission
public static function handle_confirmation_edit_submission($confirmation, $form)
{
if (empty($_POST) || !check_admin_referer('gform_confirmation_edit', 'gform_confirmation_edit')) {
return $confirmation;
}
$is_new_confirmation = !$confirmation;
if ($is_new_confirmation) {
$confirmation['id'] = uniqid();
}
$name = sanitize_text_field(rgpost('form_confirmation_name'));
$confirmation['name'] = $name;
$type = rgpost('form_confirmation');
if (!in_array($type, array('message', 'page', 'redirect'))) {
$type = 'message';
}
$confirmation['type'] = $type;
$confirmation['message'] = rgpost('form_confirmation_message');
$confirmation['disableAutoformat'] = (bool) rgpost('form_disable_autoformatting');
$confirmation['pageId'] = absint(rgpost('form_confirmation_page'));
$confirmation['url'] = rgpost('form_confirmation_url');
$query_string = '' != rgpost('form_redirect_querystring') ? rgpost('form_redirect_querystring') : rgpost('form_page_querystring');
$confirmation['queryString'] = wp_strip_all_tags($query_string);
$confirmation['isDefault'] = (bool) rgpost('is_default');
// if is default confirmation, override any submitted conditional logic with empty array
$confirmation['conditionalLogic'] = $confirmation['isDefault'] ? array() : json_decode(rgpost('conditional_logic'), ARRAY_A);
$confirmation['conditionalLogic'] = GFFormsModel::sanitize_conditional_logic($confirmation['conditionalLogic']);
$failed_validation = false;
if (!$confirmation['name']) {
$failed_validation = true;
GFCommon::add_error_message(__('You must specify a Confirmation Name.', 'gravityforms'));
}
switch ($type) {
case 'page':
if (empty($confirmation['pageId'])) {
$failed_validation = true;
GFCommon::add_error_message(__('You must select a Confirmation Page.', 'gravityforms'));
}
break;
case 'redirect':
if ((empty($confirmation['url']) || !GFCommon::is_valid_url($confirmation['url'])) && !GFCommon::has_merge_tag($confirmation['url'])) {
$failed_validation = true;
GFCommon::add_error_message(__('You must specify a valid Redirect URL.', 'gravityforms'));
}
break;
}
if ($failed_validation) {
return $confirmation;
}
// allow user to filter confirmation before save
$confirmation = gf_apply_filters('gform_pre_confirmation_save', $form['id'], $confirmation, $form, $is_new_confirmation);
// trim values
$confirmation = GFFormsModel::trim_conditional_logic_values_from_element($confirmation, $form);
// add current confirmation to confirmations array
$form['confirmations'][$confirmation['id']] = $confirmation;
// save updated confirmations array
$result = GFFormsModel::save_form_confirmations($form['id'], $form['confirmations']);
if ($result !== false) {
$url = remove_query_arg(array('cid', 'duplicatedcid'));
GFCommon::add_message(sprintf(__('Confirmation saved successfully. %sBack to confirmations.%s', 'gravityforms'), '<a href="' . esc_url($url) . '">', '</a>'));
} else {
GFCommon::add_error_message(__('There was an issue saving this confirmation.', 'gravityforms'));
}
return $confirmation;
}
示例4: get_value_entry_detail
public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen')
{
return GFCommon::is_valid_url($value) && $format == 'html' ? "<a href='{$value}' target='_blank'>{$value}</a>" : $value;
}
示例5: get_lead_field_display
public static function get_lead_field_display($field, $value, $currency = "", $use_text = false)
{
switch (RGFormsModel::get_input_type($field)) {
case "name":
if (is_array($value)) {
$prefix = trim($value[$field["id"] . ".2"]);
$first = trim($value[$field["id"] . ".3"]);
$last = trim($value[$field["id"] . ".6"]);
$suffix = trim($value[$field["id"] . ".8"]);
$name = $prefix;
$name .= !empty($name) && !empty($first) ? " {$first}" : $first;
$name .= !empty($name) && !empty($last) ? " {$last}" : $last;
$name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix;
return $name;
} else {
return $value;
}
break;
case "address":
if (is_array($value)) {
$street_value = trim($value[$field["id"] . ".1"]);
$street2_value = trim($value[$field["id"] . ".2"]);
$city_value = trim($value[$field["id"] . ".3"]);
$state_value = trim($value[$field["id"] . ".4"]);
$zip_value = trim($value[$field["id"] . ".5"]);
$country_value = trim($value[$field["id"] . ".6"]);
$address_display_format = apply_filters("gform_address_display_format", "street,city,state,zip,country");
if ($address_display_format == "zip_before_city") {
/*
Sample:
3333 Some Street
suite 16
2344 City, State
Country
*/
$addr_ary = array();
$addr_ary[] = $street_value;
if (!empty($street2_value)) {
$addr_ary[] = $street2_value;
}
$zip_line = trim($zip_value . " " . $city_value);
$zip_line .= !empty($zip_line) && !empty($state_value) ? ", {$state_value}" : $state_value;
$zip_line = trim($zip_line);
if (!empty($zip_line)) {
$addr_ary[] = $zip_line;
}
if (!empty($country_value)) {
$addr_ary[] = $country_value;
}
$address = implode("<br />", $addr_ary);
} else {
$address = $street_value;
$address .= !empty($address) && !empty($street2_value) ? "<br />{$street2_value}" : $street2_value;
$address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? "<br />{$city_value}" : $city_value;
$address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", {$state_value}" : $state_value;
$address .= !empty($address) && !empty($zip_value) ? " {$zip_value}" : $zip_value;
$address .= !empty($address) && !empty($country_value) ? "<br />{$country_value}" : $country_value;
}
//adding map link
if (!empty($address)) {
$address_qs = str_replace("<br />", " ", $address);
//replacing <br/> with spaces
$address_qs = urlencode($address_qs);
$address .= "<br/><a href='http://maps.google.com/maps?q={$address_qs}' target='_blank' class='map-it-link'>Map It</a>";
}
return $address;
} else {
return "";
}
break;
case "email":
return GFCommon::is_valid_email($value) ? "<a href='mailto:{$value}'>{$value}</a>" : $value;
break;
case "website":
return GFCommon::is_valid_url($value) ? "<a href='{$value}' target='_blank'>{$value}</a>" : $value;
break;
case "checkbox":
if (is_array($value)) {
foreach ($value as $key => $item) {
if (!empty($item)) {
$items .= "<li>" . GFCommon::selection_display($item, $field, $currency, $use_text) . "</li>";
}
}
return empty($items) ? "" : "<ul class='bulleted'>{$items}</ul>";
} else {
return $value;
}
break;
case "post_image":
list($url, $title, $caption, $description) = explode("|:|", $value);
if (!empty($url)) {
$url = str_replace(" ", "%20", $url);
$value = "<a href='{$url}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$url}' width='100' /></a>";
$value .= !empty($title) ? "<div>Title: {$title}</div>" : "";
$value .= !empty($caption) ? "<div>Caption: {$caption}</div>" : "";
$value .= !empty($description) ? "<div>Description: {$description}</div>" : "";
}
return $value;
case "fileupload":
$file_path = $value;
//.........这里部分代码省略.........
示例6: pdf_get_lead_field_display
public static function pdf_get_lead_field_display($field, $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen')
{
if ($field['type'] == 'post_category') {
$value = GFCommon::prepare_post_category_value($value, $field);
}
switch (RGFormsModel::get_input_type($field)) {
case 'name':
if (is_array($value)) {
$prefix = trim(rgget($field['id'] . '.2', $value));
$first = trim(rgget($field['id'] . '.3', $value));
$middle = trim(rgget($field['id'] . '.4', $value));
$last = trim(rgget($field['id'] . '.6', $value));
$suffix = trim(rgget($field['id'] . '.8', $value));
$name = $prefix;
$name .= !empty($name) && !empty($first) ? " {$first}" : $first;
$name .= !empty($name) && !empty($middle) ? " {$middle}" : $middle;
$name .= !empty($name) && !empty($last) ? " {$last}" : $last;
$name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix;
return $name;
} else {
return $value;
}
break;
case 'creditcard':
if (is_array($value)) {
$card_number = trim(rgget($field['id'] . '.1', $value));
$card_type = trim(rgget($field['id'] . '.4', $value));
$separator = $format == 'html' ? '<br/>' : '\\n';
return empty($card_number) ? '' : $card_type . $separator . $card_number;
} else {
return '';
}
break;
case 'address':
if (is_array($value)) {
$street_value = trim(rgget($field['id'] . '.1', $value));
$street2_value = trim(rgget($field['id'] . '.2', $value));
$city_value = trim(rgget($field['id'] . '.3', $value));
$state_value = trim(rgget($field['id'] . '.4', $value));
$zip_value = trim(rgget($field['id'] . '.5', $value));
$country_value = trim(rgget($field['id'] . '.6', $value));
$line_break = $format == 'html' ? '<br />' : '\\n';
$address_display_format = apply_filters('gform_address_display_format', 'default');
if ($address_display_format == 'zip_before_city') {
/*
Sample:
3333 Some Street
suite 16
2344 City, State
Country
*/
$addr_ary = array();
$addr_ary[] = $street_value;
if (!empty($street2_value)) {
$addr_ary[] = $street2_value;
}
$zip_line = trim($zip_value . ' ' . $city_value);
$zip_line .= !empty($zip_line) && !empty($state_value) ? ", {$state_value}" : $state_value;
$zip_line = trim($zip_line);
if (!empty($zip_line)) {
$addr_ary[] = $zip_line;
}
if (!empty($country_value)) {
$addr_ary[] = $country_value;
}
$address = implode('<br />', $addr_ary);
} else {
$address = $street_value;
$address .= !empty($address) && !empty($street2_value) ? $line_break . $street2_value : $street2_value;
$address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? $line_break . $city_value : $city_value;
$address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", {$state_value}" : $state_value;
$address .= !empty($address) && !empty($zip_value) ? " {$zip_value}" : $zip_value;
$address .= !empty($address) && !empty($country_value) ? $line_break . $country_value : $country_value;
}
return $address;
} else {
return '';
}
break;
case 'email':
return GFCommon::is_valid_email($value) && $format == 'html' ? '<a href="mailto:' . $value . '">' . $value . '</a>' : $value;
break;
case 'website':
return GFCommon::is_valid_url($value) && $format == 'html' ? '<a href="' . $value . '" target="_blank">' . $value . '</a>' : $value;
break;
case 'checkbox':
if (is_array($value)) {
$items = '';
foreach ($value as $key => $item) {
if (!empty($item)) {
switch ($format) {
case 'text':
$items .= GFCommon::selection_display($item, $field, $currency, true) . ', ';
break;
default:
$items .= '<li>' . GFCommon::selection_display($item, $field, $currency, true) . '</li>';
break;
}
}
}
//.........这里部分代码省略.........
示例7: validate
//.........这里部分代码省略.........
$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;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid time.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
break;
case "website":
if (empty($value) || $value == "http://") {
$value = "";
if ($field["isRequired"]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
}
if (!empty($value) && !GFCommon::is_valid_url($value)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid Website URL (i.e. http://www.gravityforms.com).", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
break;
case "captcha":
switch ($field["captchaType"]) {
case "simple_captcha":
if (class_exists("ReallySimpleCaptcha")) {
$prefix = $_POST["input_captcha_prefix_{$field["id"]}"];
$captcha_obj = GFCommon::get_simple_captcha();
if (!$captcha_obj->check($prefix, str_replace(" ", "", $value))) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("The CAPTCHA wasn't entered correctly. Go back and try it again.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
//removes current captcha file
$captcha_obj->remove($prefix);
//removes old files in captcha folder (older than 1 hour);
$captcha_obj->cleanup();
}
break;
case "math":
$prefixes = explode(",", $_POST["input_captcha_prefix_{$field["id"]}"]);
$captcha_obj = GFCommon::get_simple_captcha();
//finding first number
$first = 0;
for ($first = 0; $first < 10; $first++) {
if ($captcha_obj->check($prefixes[0], $first)) {
break;
}
}
示例8: validate
//.........这里部分代码省略.........
break;
case "dmy_dash":
$format_name = "dd-mm-yyyy";
break;
case "dmy_dot":
$format_name = "dd.mm.yyyy";
break;
case "ymd_slash":
$format_name = "yyyy/mm/dd";
break;
case "ymd_dash":
$format_name = "yyyy-mm-dd";
break;
case "ymd_dot":
$format_name = "yyyy.mm.dd";
break;
}
$message = $field["dateType"] == "datepicker" ? sprintf(__("Please enter a valid date in the format (%s).", "gravityforms"), $format_name) : __("Please enter a valid date.", "gravityforms");
$field["validation_message"] = empty($field["errorMessage"]) ? $message : $field["errorMessage"];
}
}
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);
$min_hour = rgar($field, "timeFormat") == "24" ? 0 : 1;
$max_hour = rgar($field, "timeFormat") == "24" ? 23 : 12;
if (!$is_valid_format || $hour < $min_hour || $hour > $max_hour || $minute < 0 || $minute >= 60) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid time.", "gravityforms") : $field["errorMessage"];
}
break;
case "website":
if (empty($value) || $value == "http://") {
$value = "";
if ($field["isRequired"]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
}
}
if (!empty($value) && !GFCommon::is_valid_url($value)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid Website URL (i.e. http://www.gravityforms.com).", "gravityforms") : $field["errorMessage"];
}
break;
case "calculation":
$quantity_id = $field["id"] . ".3";
$quantity = rgget($quantity_id, $value);
if ($field["isRequired"] && rgblank($quantity) && !rgar($field, "disableQuantity")) {
$field["failed_validation"] = true;
$field["validation_message"] = rgempty("errorMessage", $field) ? __("This field is required.", "gravityforms") : rgar($field, "errorMessage");
} else {
if (!empty($quantity) && (!is_numeric($quantity) || intval($quantity) != floatval($quantity) || intval($quantity) < 0)) {
$field["failed_validation"] = true;
$field["validation_message"] = __("Please enter a valid quantity", "gravityforms");
}
}
break;
case "radio":
if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
$value = rgpost("input_{$field['id']}_other");
}
if ($field["isRequired"] && rgar($field, 'enableOtherChoice') && $value == GFCommon::get_other_choice_value()) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
}
break;
}
}
}
}
$custom_validation_result = apply_filters("gform_field_validation", array("is_valid" => rgar($field, "failed_validation") ? false : true, "message" => rgar($field, "validation_message")), $value, $form, $field);
$custom_validation_result = apply_filters("gform_field_validation_{$form["id"]}", $custom_validation_result, $value, $form, $field);
$custom_validation_result = apply_filters("gform_field_validation_{$form["id"]}_{$field["id"]}", $custom_validation_result, $value, $form, $field);
$field["failed_validation"] = rgar($custom_validation_result, "is_valid") ? false : true;
$field["validation_message"] = rgar($custom_validation_result, "message");
}
$is_valid = true;
foreach ($form["fields"] as $f) {
if (rgar($f, "failed_validation")) {
$is_valid = false;
break;
}
}
$validation_result = apply_filters("gform_validation_{$form["id"]}", apply_filters("gform_validation", array("is_valid" => $is_valid, "form" => $form)));
$is_valid = $validation_result["is_valid"];
$form = $validation_result["form"];
return $is_valid;
}
示例9: validate
//.........这里部分代码省略.........
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;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid time.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
break;
case "website":
if ($value == "http://") {
$value = "";
if ($field["isRequired"]) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a value.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
}
if (!empty($value) && !GFCommon::is_valid_url($value)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid Website URL (i.e. http://www.gravityforms.com).", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
break;
case "captcha":
if (!function_exists("recaptcha_get_html")) {
require_once GFCommon::get_base_path() . '/recaptchalib.php';
}
$privatekey = get_option("rg_gforms_captcha_private_key");
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("The reCAPTCHA wasn't entered correctly. Go back and try it again.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
}
break;
case "fileupload":
case "post_image":
$info = pathinfo($_FILES["input_" . $field["id"]]["name"]);
$allowedExtensions = self::clean_extensions(explode(",", strtolower($field["allowedExtensions"])));
$extension = strtolower($info["extension"]);
if (empty($field["allowedExtensions"]) && in_array($extension, array("php", "asp", "exe", "com", "htaccess"))) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? __("The uploaded file type is not allowed.", "gravityforms") : $field["errorMessage"];
$is_valid = false;
} else {
if (!empty($field["allowedExtensions"]) && !empty($info["basename"]) && !in_array($extension, $allowedExtensions)) {
$field["failed_validation"] = true;
$field["validation_message"] = empty($field["errorMessage"]) ? sprintf(__("The uploaded file type is not allowed. Must be one of the following: %s", "gravityforms"), strtolower($field["allowedExtensions"])) : $field["errorMessage"];
$is_valid = false;
}
}
break;
}
}
}
}
return $is_valid;
}
示例10: get_lead_field_display
public static function get_lead_field_display($field, $value)
{
switch (RGFormsModel::get_input_type($field)) {
case "name":
if (is_array($value)) {
$prefix = trim($value[$field["id"] . ".2"]);
$first = trim($value[$field["id"] . ".3"]);
$last = trim($value[$field["id"] . ".6"]);
$suffix = trim($value[$field["id"] . ".8"]);
$name = $prefix;
$name .= !empty($name) && !empty($first) ? " {$first}" : $first;
$name .= !empty($name) && !empty($last) ? " {$last}" : $last;
$name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix;
return $name;
} else {
return $value;
}
break;
case "address":
if (is_array($value)) {
$street_value = trim($value[$field["id"] . ".1"]);
$street2_value = trim($value[$field["id"] . ".2"]);
$city_value = trim($value[$field["id"] . ".3"]);
$state_value = trim($value[$field["id"] . ".4"]);
$zip_value = trim($value[$field["id"] . ".5"]);
$country_value = trim($value[$field["id"] . ".6"]);
$address = $street_value;
$address .= !empty($address) && !empty($street2_value) ? " {$street2_value}" : $street2_value;
$address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? "<br />{$city_value}" : $city_value;
$address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", {$state_value}" : $state_value;
$address .= !empty($address) && !empty($zip_value) ? " {$zip_value}" : $zip_value;
$address .= !empty($address) && !empty($country_value) ? "<br />{$country_value}" : $country_value;
//adding map link
if (!empty($address)) {
$address_qs = str_replace("<br />", " ", $address);
//replacing <br/> with spaces
$address_qs = urlencode($address_qs);
$address .= "<br/><a href='http://maps.google.com/maps?q={$address_qs}' target='_blank' class='map-it-link'>Map It</a>";
}
return $address;
} else {
return "";
}
break;
case "email":
return GFCommon::is_valid_email($value) ? "<a href='mailto:{$value}'>{$value}</a>" : $value;
break;
case "website":
return GFCommon::is_valid_url($value) ? "<a href='{$value}' target='_blank'>{$value}</a>" : $value;
break;
case "checkbox":
if (is_array($value)) {
foreach ($value as $key => $item) {
if (!empty($item)) {
$items .= "<li>{$item}</li>";
}
}
return empty($items) ? "" : "<ul class='bulleted'>{$items}</ul>";
} else {
return $value;
}
break;
case "post_image":
list($url, $title, $caption, $description) = explode("|:|", $value);
if (!empty($url)) {
$url = str_replace(" ", "%20", $url);
$value = "<a href='{$url}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$url}' width='100' /></a>";
$value .= !empty($title) ? "<div>Title: {$title}</div>" : "";
$value .= !empty($caption) ? "<div>Caption: {$caption}</div>" : "";
$value .= !empty($description) ? "<div>Description: {$description}</div>" : "";
}
return $value;
case "fileupload":
$file_path = $value;
if (!empty($file_path)) {
$info = pathinfo($file_path);
$file_path = esc_attr(str_replace(" ", "%20", $file_path));
$value = "<a href='{$file_path}' target='_blank' title='" . __("Click to view", "gravityforms") . "'>" . $info["basename"] . "</a>";
}
return $value;
break;
case "date":
return GFCommon::date_display($value, $field["dateFormat"]);
break;
default:
return nl2br($value);
break;
}
}