public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen') { return GFCommon::is_valid_email($value) && $format == 'html' ? "<a href='mailto:{$value}'>{$value}</a>" : $value; }
public static function handle_save_email_confirmation($form, $ajax) { $resume_email = $_POST['gform_resume_email']; if (!GFCommon::is_valid_email($resume_email)) { GFCommon::log_debug('GFFormDisplay::handle_save_email_confirmation(): Invalid email address: ' . $resume_email); return new WP_Error('invalid_email'); } $resume_token = $_POST['gform_resume_token']; $submission_details = GFFormsModel::get_incomplete_submission_values($resume_token); $submission_json = $submission_details['submission']; $submission = json_decode($submission_json, true); $entry = $submission['partial_entry']; $form = self::update_confirmation($form, $entry, 'form_save_email_sent'); $confirmation = '<div class="form_saved_message_sent"><span>' . rgar($form['confirmation'], 'message') . '</span></div>'; $nl2br = rgar($form['confirmation'], 'disableAutoformat') ? false : true; $save_email_confirmation = self::replace_save_variables($confirmation, $form, $resume_token, $resume_email); $save_email_confirmation = GFCommon::replace_variables($save_email_confirmation, $form, $entry, false, true, $nl2br); $save_email_confirmation = GFCommon::gform_do_shortcode($save_email_confirmation); $form_id = absint($form['id']); $has_pages = self::has_pages($form); $default_anchor = $has_pages || $ajax ? true : false; $use_anchor = gf_apply_filters(array('gform_confirmation_anchor', $form_id), $default_anchor); if ($use_anchor !== false) { $save_email_confirmation = "<a id='gf_{$form_id}' class='gform_anchor' ></a>" . $save_email_confirmation; } if ($ajax) { $save_email_confirmation = "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $save_email_confirmation . '</body></html>'; } GFCommon::log_debug('GFFormDisplay::handle_save_email_confirmation(): Confirmation => ' . print_r($save_email_confirmation, true)); return $save_email_confirmation; }
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"); if (empty($security_code)) { $field["failed_validation"] = true; $field["validation_message"] = __("Please enter your card's security code.", "gravityforms"); } else { if (!$card_type) { $field["failed_validation"] = true; $field["validation_message"] = __("Invalid credit card number.", "gravityforms"); } else { if (!GFCommon::is_card_supported($field, $card_type["slug"])) { $field["failed_validation"] = true; $field["validation_message"] = $card_type["name"] . " " . __("is not supported. Please enter one of the supported credit cards.", "gravityforms"); } } } } } 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"); } } } break; case "donation": case "price": if (!class_exists("RGCurrency")) { require_once "currency.php"; } $donation = GFCommon::to_number($value); if (!rgblank($value) && ($donation === false || $donation < 0)) { $field["failed_validation"] = true; $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid amount.", "gravityforms") : $field["errorMessage"]; } break; case "number": if (!rgblank($value) && !self::validate_range($field, $value) && !GFCommon::has_field_calculation($field)) { $field["failed_validation"] = true; $field["validation_message"] = empty($field["errorMessage"]) ? GFCommon::get_range_message($field) : $field["errorMessage"]; } else { if ($field["type"] == "quantity" && intval($value) != $value) { $field["failed_validation"] = true; $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid quantity. Quantity cannot contain decimals.", "gravityforms") : $field["errorMessage"]; } } 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"]; } } break; case "date": if (is_array($value) && rgempty(0, $value) && rgempty(1, $value) && rgempty(2, $value)) { $value = null; } if (!empty($value)) { $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"]; $date = GFCommon::parse_date($value, $format); if (empty($date) || !self::checkdate($date["month"], $date["day"], $date["year"])) { $field["failed_validation"] = true; $format_name = ""; switch ($format) { case "mdy": $format_name = "mm/dd/yyyy"; break; case "dmy": $format_name = "dd/mm/yyyy"; 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 "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)) { break; } } //if it is a +, perform the sum if ($captcha_obj->check($prefixes[1], "+")) { $result = $first + $second; } else { $result = $first - $second; } if (intval($result) != intval($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; default: 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"]; } } break; case "fileupload": case "post_image": $info = pathinfo($_FILES["input_" . $field["id"]]["name"]); $allowedExtensions = self::clean_extensions(explode(",", strtolower($field["allowedExtensions"]))); $extension = strtolower(rgget("extension", $info)); 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"]; } 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"]; } } break; case "calculation": case "singleproduct": case "hiddenproduct": $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))) { $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; }
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: $items .= "<li>" . GFCommon::selection_display($item, $field, $currency, $use_text) . "</li>"; break; } } } if (empty($items)) { return ""; } else { if ($format == "text") { return substr($items, 0, strlen($items) - 2); //removing last comma } else { return "<ul class='bulleted'>{$items}</ul>"; } } } else { return $value; } break; case "post_image": $ary = explode("|:|", $value); $url = count($ary) > 0 ? $ary[0] : ""; $title = count($ary) > 1 ? $ary[1] : ""; $caption = count($ary) > 2 ? $ary[2] : ""; $description = count($ary) > 3 ? $ary[3] : ""; if (!empty($url)) { $url = str_replace(" ", "%20", $url); switch ($format) { case "text": $value = $url; $value .= !empty($title) ? "\n\n" . $field["label"] . " (" . __("Title", "gravityforms") . "): " . $title : ""; $value .= !empty($caption) ? "\n\n" . $field["label"] . " (" . __("Caption", "gravityforms") . "): " . $caption : ""; $value .= !empty($description) ? "\n\n" . $field["label"] . " (" . __("Description", "gravityforms") . "): " . $description : ""; break; default: $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>" : ""; break; } } 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 = $format == "text" ? $file_path : "<a href='{$file_path}' target='_blank' title='" . __("Click to view", "gravityforms") . "'>" . $info["basename"] . "</a>"; } return $value; break; case "date": return GFCommon::date_display($value, rgar($field, "dateFormat")); break; case "radio": case "select": return GFCommon::selection_display($value, $field, $currency, $use_text); break; case "multiselect": if (empty($value) || $format == "text") { return $value; } $value = explode(",", $value); $items = ''; foreach ($value as $item) { $items .= "<li>" . GFCommon::selection_display($item, $field, $currency, $use_text) . "</li>"; } return "<ul class='bulleted'>{$items}</ul>"; break; case "calculation": case "singleproduct": if (is_array($value)) { $product_name = trim($value[$field["id"] . ".1"]); $price = trim($value[$field["id"] . ".2"]); $quantity = trim($value[$field["id"] . ".3"]); $product = $product_name . ", " . __("Qty: ", "gravityforms") . $quantity . ", " . __("Price: ", "gravityforms") . $price; return $product; } else { return ""; } break; case "number": return GFCommon::format_number($value, rgar($field, "numberFormat")); break; case "singleshipping": case "donation": case "total": case "price": return GFCommon::to_money($value, $currency); case "list": if (empty($value)) { return ""; } $value = unserialize($value); $has_columns = is_array($value[0]); if (!$has_columns) { $items = ''; foreach ($value as $key => $item) { if (!empty($item)) { switch ($format) { case "text": $items .= $item . ", "; break; case "url": $items .= $item . ","; break; default: if ($media == "email") { $items .= "<li>{$item}</li>"; } else { $items .= "<li>{$item}</li>"; } break; } } } if (empty($items)) { return ""; } else { if ($format == "text") { return substr($items, 0, strlen($items) - 2); //removing last comma } else { if ($format == "url") { return substr($items, 0, strlen($items) - 1); //removing last comma } else { if ($media == "email") { return "<ul class='bulleted'>{$items}</ul>"; } else { return "<ul class='bulleted'>{$items}</ul>"; } } } } } else { if (is_array($value)) { $columns = array_keys($value[0]); $list = ""; switch ($format) { case "text": $is_first_row = true; foreach ($value as $item) { if (!$is_first_row) { $list .= "\n\n" . $field["label"] . ": "; } $list .= implode(",", array_values($item)); $is_first_row = false; } break; case "url": foreach ($value as $item) { $list .= implode("|", array_values($item)) . ","; } if (!empty($list)) { $list = substr($list, 0, strlen($list) - 1); } break; default: if ($media == "email") { $list = "<table class='gfield_list' style='border-top: 1px solid #DFDFDF; border-left: 1px solid #DFDFDF; border-spacing: 0; padding: 0; margin: 2px 0 6px; width: 100%'><thead><tr>"; //reading columns from entry data foreach ($columns as $column) { $list .= "<th style='background-image: none; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; padding: 6px 10px; font-family: sans-serif; font-size: 12px; font-weight: bold; background-color: #F1F1F1; color:#333; text-align:left'>" . esc_html($column) . "</th>"; } $list .= "</tr></thead>"; $list .= "<tbody style='background-color: #F9F9F9'>"; foreach ($value as $item) { $list .= "<tr>"; foreach ($columns as $column) { $val = rgar($item, $column); $list .= "<td style='padding: 6px 10px; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; border-top: 1px solid #FFF; font-family: sans-serif; font-size:12px;'>{$val}</td>"; } $list .= "</tr>"; } $list .= "<tbody></table>"; } else { $list = "<table class='gfield_list'><thead><tr>"; //reading columns from entry data foreach ($columns as $column) { $list .= "<th>" . esc_html($column) . "</th>"; } $list .= "</tr></thead>"; $list .= "<tbody>"; foreach ($value as $item) { $list .= "<tr>"; foreach ($columns as $column) { $val = rgar($item, $column); $list .= "<td>{$val}</td>"; } $list .= "</tr>"; } $list .= "<tbody></table>"; } break; } return $list; } } return ""; break; default: if (!is_array($value)) { return nl2br($value); } break; } }
private static function edit_page() { ?> <style> #paypal_submit_container{clear:both;} .paypal_col_heading{padding-bottom:2px; border-bottom: 1px solid #ccc; font-weight:bold; width:120px;} .paypal_field_cell {padding: 6px 17px 0 0; margin-right:15px;} .paypal_validation_error{ background-color:#FFDFDF; margin-top:4px; margin-bottom:6px; padding-top:6px; padding-bottom:6px; border:1px dotted #C89797;} .paypal_validation_error span {color: red;} .left_header{float:left; width:200px;} .margin_vertical_10{margin: 10px 0; padding-left:5px;} .margin_vertical_30{margin: 30px 0; padding-left:5px;} .width-1{width:300px;} .gf_paypal_invalid_form{margin-top:30px; background-color:#FFEBE8;border:1px solid #CC0000; padding:10px; width:600px;} </style> <script type="text/javascript"> var form = Array(); function ToggleNotifications(){ var container = jQuery("#gf_paypal_notification_container"); var isChecked = jQuery("#gf_paypal_delay_notifications").is(":checked"); if(isChecked){ container.slideDown(); var isLoaded = jQuery(".gf_paypal_notification").length > 0 if(!isLoaded){ container.html("<li><img src='<?php echo self::get_base_url(); ?> /images/loading.gif' title='<?php _e("Please wait...", "gravityformspaypal"); ?> '></li>"); jQuery.post(ajaxurl, { action: "gf_paypal_load_notifications", form_id: form["id"], }, function(response){ var notifications = jQuery.parseJSON(response); if(!notifications){ container.html("<li><div class='error' padding='20px;'><?php _e("Notifications could not be loaded. Please try again later or contact support", "gravityformspaypal"); ?> </div></li>"); } else if(notifications.length == 0){ container.html("<li><div class='error' padding='20px;'><?php _e("The form selected does not have any notifications.", "gravityformspaypal"); ?> </div></li>"); } else{ var str = ""; for(var i=0; i<notifications.length; i++){ str += "<li class='gf_paypal_notification'>" + "<input type='checkbox' value='" + notifications[i]["id"] + "' name='gf_paypal_selected_notifications[]' id='gf_paypal_selected_notifications' checked='checked' /> " + "<label class='inline' for='gf_paypal_selected_notifications'>" + notifications[i]["name"] + "</label>"; + "</li>"; } container.html(str); } } ); } jQuery(".gf_paypal_notification input").prop("checked", true); } else{ container.slideUp(); jQuery(".gf_paypal_notification input").prop("checked", false); } } </script> <div class="wrap"> <img alt="<?php _e("PayPal", "gravityformspaypal"); ?> " style="margin: 15px 7px 0pt 0pt; float: left;" src="<?php echo self::get_base_url(); ?> /images/paypal_wordpress_icon_32.png"/> <h2><?php _e("PayPal Transaction Settings", "gravityformspaypal"); ?> </h2> <?php //getting setting id (0 when creating a new one) $id = !empty($_POST["paypal_setting_id"]) ? $_POST["paypal_setting_id"] : absint($_GET["id"]); $config = empty($id) ? array("meta" => array(), "is_active" => true) : GFPayPalData::get_feed($id); $is_validation_error = false; $config["form_id"] = rgpost("gf_paypal_submit") ? absint(rgpost("gf_paypal_form")) : $config["form_id"]; $form = isset($config["form_id"]) && $config["form_id"] ? $form = RGFormsModel::get_form_meta($config["form_id"]) : array(); //updating meta information if (rgpost("gf_paypal_submit")) { $config["meta"]["email"] = trim(rgpost("gf_paypal_email")); $config["meta"]["mode"] = rgpost("gf_paypal_mode"); $config["meta"]["type"] = rgpost("gf_paypal_type"); $config["meta"]["style"] = rgpost("gf_paypal_page_style"); $config["meta"]["continue_text"] = rgpost("gf_paypal_continue_text"); $config["meta"]["cancel_url"] = rgpost("gf_paypal_cancel_url"); $config["meta"]["disable_note"] = rgpost("gf_paypal_disable_note"); $config["meta"]["disable_shipping"] = rgpost('gf_paypal_disable_shipping'); $config["meta"]["delay_post"] = rgpost('gf_paypal_delay_post'); $config["meta"]["update_post_action"] = rgpost('gf_paypal_update_action'); if (isset($form["notifications"])) { //new notification settings $config["meta"]["delay_notifications"] = rgpost('gf_paypal_delay_notifications'); $config["meta"]["selected_notifications"] = $config["meta"]["delay_notifications"] ? rgpost('gf_paypal_selected_notifications') : array(); if (isset($config["meta"]["delay_autoresponder"])) { unset($config["meta"]["delay_autoresponder"]); } if (isset($config["meta"]["delay_notification"])) { unset($config["meta"]["delay_notification"]); } } else { //legacy notification settings (for backwards compatibility) $config["meta"]["delay_autoresponder"] = rgpost('gf_paypal_delay_autoresponder'); $config["meta"]["delay_notification"] = rgpost('gf_paypal_delay_notification'); if (isset($config["meta"]["delay_notifications"])) { unset($config["meta"]["delay_notifications"]); } if (isset($config["meta"]["selected_notifications"])) { unset($config["meta"]["selected_notifications"]); } } // paypal conditional $config["meta"]["paypal_conditional_enabled"] = rgpost('gf_paypal_conditional_enabled'); $config["meta"]["paypal_conditional_field_id"] = rgpost('gf_paypal_conditional_field_id'); $config["meta"]["paypal_conditional_operator"] = rgpost('gf_paypal_conditional_operator'); $config["meta"]["paypal_conditional_value"] = rgpost('gf_paypal_conditional_value'); //recurring fields $config["meta"]["recurring_amount_field"] = rgpost("gf_paypal_recurring_amount"); $config["meta"]["billing_cycle_number"] = rgpost("gf_paypal_billing_cycle_number"); $config["meta"]["billing_cycle_type"] = rgpost("gf_paypal_billing_cycle_type"); $config["meta"]["recurring_times"] = rgpost("gf_paypal_recurring_times"); $config["meta"]["trial_period_enabled"] = rgpost('gf_paypal_trial_period'); $config["meta"]["trial_amount"] = rgpost('gf_paypal_trial_amount'); $config["meta"]["trial_period_number"] = rgpost('gf_paypal_trial_period_number'); $config["meta"]["trial_period_type"] = rgpost('gf_paypal_trial_period_type'); $config["meta"]["recurring_retry"] = rgpost('gf_paypal_recurring_retry'); //----------------- $customer_fields = self::get_customer_fields(); $config["meta"]["customer_fields"] = array(); foreach ($customer_fields as $field) { $config["meta"]["customer_fields"][$field["name"]] = $_POST["paypal_customer_field_{$field["name"]}"]; } $config = apply_filters('gform_paypal_save_config', $config); $is_validation_error = apply_filters("gform_paypal_config_validation", false, $config); if (GFCommon::is_valid_email($config["meta"]["email"]) && !$is_validation_error) { $id = GFPayPalData::update_feed($id, $config["form_id"], $config["is_active"], $config["meta"]); ?> <div class="updated fade" style="padding:6px"><?php echo sprintf(__("Feed Updated. %sback to list%s", "gravityformspaypal"), "<a href='?page=gf_paypal'>", "</a>"); ?> </div> <?php } else { $is_validation_error = true; } } ?> <form method="post" action=""> <input type="hidden" name="paypal_setting_id" value="<?php echo $id; ?> " /> <div class="margin_vertical_10 <?php echo $is_validation_error ? "paypal_validation_error" : ""; ?> "> <?php if ($is_validation_error) { ?> <span><?php _e('There was an issue saving your feed. Please address the errors below and try again.'); ?> </span> <?php } ?> </div> <!-- / validation message --> <div class="margin_vertical_10<?php echo $is_validation_error && !GFCommon::is_valid_email($config["meta"]["email"]) ? " paypal_validation_error" : ""; ?> "> <label class="left_header" for="gf_paypal_email"><?php _e("PayPal Email Address", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_email_address"); ?> </label> <input type="text" name="gf_paypal_email" id="gf_paypal_email" value="<?php echo rgar($config['meta'], 'email'); ?> " class="width-1"/> <?php if ($is_validation_error && !GFCommon::is_valid_email($config["meta"]["email"])) { ?> <span>Please enter a valid email address.</span> <?php } ?> </div> <div class="margin_vertical_10"> <label class="left_header"><?php _e("Mode", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_mode"); ?> </label> <input type="radio" name="gf_paypal_mode" id="gf_paypal_mode_production" value="production" <?php echo rgar($config['meta'], 'mode') != "test" ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_mode_production"><?php _e("Production", "gravityformspaypal"); ?> </label> <input type="radio" name="gf_paypal_mode" id="gf_paypal_mode_test" value="test" <?php echo rgar($config['meta'], 'mode') == "test" ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_mode_test"><?php _e("Test", "gravityformspaypal"); ?> </label> </div> <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_type"><?php _e("Transaction Type", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_transaction_type"); ?> </label> <select id="gf_paypal_type" name="gf_paypal_type" onchange="SelectType(jQuery(this).val());"> <option value=""><?php _e("Select a transaction type", "gravityformspaypal"); ?> </option> <option value="product" <?php echo rgar($config['meta'], 'type') == "product" ? "selected='selected'" : ""; ?> ><?php _e("Products and Services", "gravityformspaypal"); ?> </option> <option value="donation" <?php echo rgar($config['meta'], 'type') == "donation" ? "selected='selected'" : ""; ?> ><?php _e("Donations", "gravityformspaypal"); ?> </option> <option value="subscription" <?php echo rgar($config['meta'], 'type') == "subscription" ? "selected='selected'" : ""; ?> ><?php _e("Subscriptions", "gravityformspaypal"); ?> </option> </select> </div> <div id="paypal_form_container" valign="top" class="margin_vertical_10" <?php echo empty($config["meta"]["type"]) ? "style='display:none;'" : ""; ?> > <label for="gf_paypal_form" class="left_header"><?php _e("Gravity Form", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_gravity_form"); ?> </label> <select id="gf_paypal_form" name="gf_paypal_form" onchange="SelectForm(jQuery('#gf_paypal_type').val(), jQuery(this).val(), '<?php echo rgar($config, 'id'); ?> ');"> <option value=""><?php _e("Select a form", "gravityformspaypal"); ?> </option> <?php $active_form = rgar($config, 'form_id'); $available_forms = GFPayPalData::get_available_forms($active_form); foreach ($available_forms as $current_form) { $selected = absint($current_form->id) == rgar($config, 'form_id') ? 'selected="selected"' : ''; ?> <option value="<?php echo absint($current_form->id); ?> " <?php echo $selected; ?> ><?php echo esc_html($current_form->title); ?> </option> <?php } ?> </select> <img src="<?php echo GFPayPal::get_base_url(); ?> /images/loading.gif" id="paypal_wait" style="display: none;"/> <div id="gf_paypal_invalid_product_form" class="gf_paypal_invalid_form" style="display:none;"> <?php _e("The form selected does not have any Product fields. Please add a Product field to the form and try again.", "gravityformspaypal"); ?> </div> <div id="gf_paypal_invalid_donation_form" class="gf_paypal_invalid_form" style="display:none;"> <?php _e("The form selected does not have any Product fields. Please add a Product field to the form and try again.", "gravityformspaypal"); ?> </div> </div> <div id="paypal_field_group" valign="top" <?php echo empty($config["meta"]["type"]) || empty($config["form_id"]) ? "style='display:none;'" : ""; ?> > <div id="paypal_field_container_subscription" class="paypal_field_container" valign="top" <?php echo rgars($config, "meta/type") != "subscription" ? "style='display:none;'" : ""; ?> > <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_recurring_amount"><?php _e("Recurring Amount", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_recurring_amount"); ?> </label> <select id="gf_paypal_recurring_amount" name="gf_paypal_recurring_amount"> <?php echo self::get_product_options($form, rgar($config["meta"], "recurring_amount_field")); ?> </select> </div> <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_billing_cycle_number"><?php _e("Billing Cycle", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_billing_cycle"); ?> </label> <select id="gf_paypal_billing_cycle_number" name="gf_paypal_billing_cycle_number"> <?php for ($i = 1; $i <= 100; $i++) { ?> <option value="<?php echo $i; ?> " <?php echo rgar($config["meta"], "billing_cycle_number") == $i ? "selected='selected'" : ""; ?> ><?php echo $i; ?> </option> <?php } ?> </select> <select id="gf_paypal_billing_cycle_type" name="gf_paypal_billing_cycle_type" onchange="SetPeriodNumber('#gf_paypal_billing_cycle_number', jQuery(this).val());"> <option value="D" <?php echo rgars($config, "meta/billing_cycle_type") == "D" ? "selected='selected'" : ""; ?> ><?php _e("day(s)", "gravityformspaypal"); ?> </option> <option value="W" <?php echo rgars($config, "meta/billing_cycle_type") == "W" ? "selected='selected'" : ""; ?> ><?php _e("week(s)", "gravityformspaypal"); ?> </option> <option value="M" <?php echo rgars($config, "meta/billing_cycle_type") == "M" || strlen(rgars($config, "meta/billing_cycle_type")) == 0 ? "selected='selected'" : ""; ?> ><?php _e("month(s)", "gravityformspaypal"); ?> </option> <option value="Y" <?php echo rgars($config, "meta/billing_cycle_type") == "Y" ? "selected='selected'" : ""; ?> ><?php _e("year(s)", "gravityformspaypal"); ?> </option> </select> </div> <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_recurring_times"><?php _e("Recurring Times", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_recurring_times"); ?> </label> <select id="gf_paypal_recurring_times" name="gf_paypal_recurring_times"> <option value=""><?php _e("Infinite", "gravityformspaypal"); ?> </option> <?php for ($i = 2; $i <= 30; $i++) { $selected = $i == rgar($config["meta"], "recurring_times") ? 'selected="selected"' : ''; ?> <option value="<?php echo $i; ?> " <?php echo $selected; ?> ><?php echo $i; ?> </option> <?php } ?> </select> <input type="checkbox" name="gf_paypal_recurring_retry" id="gf_paypal_recurring_retry" value="1" <?php echo rgars($config, "meta/recurring_retry") ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_recurring_retry"><?php _e("Try to bill again after failed attempt.", "gravityformspaypal"); ?> </label> </div> <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_trial_period"><?php _e("Trial Period", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_trial_period_enable"); ?> </label> <input type="checkbox" name="gf_paypal_trial_period" id="gf_paypal_trial_period" value="1" onclick="if(jQuery(this).is(':checked')) jQuery('#paypal_trial_period_container').show('slow'); else jQuery('#paypal_trial_period_container').hide('slow');" <?php echo rgars($config, "meta/trial_period_enabled") ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_trial_period"><?php _e("Enable", "gravityformspaypal"); ?> </label> </div> <div id="paypal_trial_period_container" <?php echo rgars($config, "meta/trial_period_enabled") ? "" : "style='display:none;'"; ?> > <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_trial_amount"><?php _e("Trial Amount", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_trial_amount"); ?> </label> <input type="text" name="gf_paypal_trial_amount" id="gf_paypal_trial_amount" value="<?php echo rgars($config, "meta/trial_amount"); ?> "/> </div> <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_trial_period_number"><?php _e("Trial Period", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_trial_period"); ?> </label> <select id="gf_paypal_trial_period_number" name="gf_paypal_trial_period_number"> <?php for ($i = 1; $i <= 100; $i++) { ?> <option value="<?php echo $i; ?> " <?php echo rgars($config, "meta/trial_period_number") == $i ? "selected='selected'" : ""; ?> ><?php echo $i; ?> </option> <?php } ?> </select> <select id="gf_paypal_trial_period_type" name="gf_paypal_trial_period_type" onchange="SetPeriodNumber('#gf_paypal_trial_period_number', jQuery(this).val());"> <option value="D" <?php echo rgars($config, "meta/trial_period_type") == "D" ? "selected='selected'" : ""; ?> ><?php _e("day(s)", "gravityformspaypal"); ?> </option> <option value="W" <?php echo rgars($config, "meta/trial_period_type") == "W" ? "selected='selected'" : ""; ?> ><?php _e("week(s)", "gravityformspaypal"); ?> </option> <option value="M" <?php echo rgars($config, "meta/trial_period_type") == "M" || empty($config["meta"]["trial_period_type"]) ? "selected='selected'" : ""; ?> ><?php _e("month(s)", "gravityformspaypal"); ?> </option> <option value="Y" <?php echo rgars($config, "meta/trial_period_type") == "Y" ? "selected='selected'" : ""; ?> ><?php _e("year(s)", "gravityformspaypal"); ?> </option> </select> </div> </div> </div> <div class="margin_vertical_10"> <label class="left_header"><?php _e("Customer", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_customer"); ?> </label> <div id="paypal_customer_fields"> <?php if (!empty($form)) { echo self::get_customer_information($form, $config); } ?> </div> </div> <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_page_style"><?php _e("Page Style", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_page_style"); ?> </label> <input type="text" name="gf_paypal_page_style" id="gf_paypal_page_style" class="width-1" value="<?php echo rgars($config, "meta/style"); ?> "/> </div> <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_continue_text"><?php _e("Continue Button Label", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_continue_button_label"); ?> </label> <input type="text" name="gf_paypal_continue_text" id="gf_paypal_continue_text" class="width-1" value="<?php echo rgars($config, "meta/continue_text"); ?> "/> </div> <div class="margin_vertical_10"> <label class="left_header" for="gf_paypal_cancel_url"><?php _e("Cancel URL", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_cancel_url"); ?> </label> <input type="text" name="gf_paypal_cancel_url" id="gf_paypal_cancel_url" class="width-1" value="<?php echo rgars($config, "meta/cancel_url"); ?> "/> </div> <div class="margin_vertical_10"> <label class="left_header"><?php _e("Options", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_options"); ?> </label> <ul style="overflow:hidden;"> <li> <input type="checkbox" name="gf_paypal_disable_shipping" id="gf_paypal_disable_shipping" value="1" <?php echo rgar($config['meta'], 'disable_shipping') ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_disable_shipping"><?php _e("Do not prompt buyer to include a shipping address.", "gravityformspaypal"); ?> </label> </li> <li> <input type="checkbox" name="gf_paypal_disable_note" id="gf_paypal_disable_note" value="1" <?php echo rgar($config['meta'], 'disable_note') ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_disable_note"><?php _e("Do not prompt buyer to include a note with payment.", "gravityformspaypal"); ?> </label> </li> <li id="paypal_delay_notification" <?php echo isset($form["notifications"]) ? "style='display:none;'" : ""; ?> > <input type="checkbox" name="gf_paypal_delay_notification" id="gf_paypal_delay_notification" value="1" <?php echo rgar($config["meta"], 'delay_notification') ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_delay_notification"><?php _e("Send admin notification only when payment is received.", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_delay_admin_notification"); ?> </label> </li> <li id="paypal_delay_autoresponder" <?php echo isset($form["notifications"]) ? "style='display:none;'" : ""; ?> > <input type="checkbox" name="gf_paypal_delay_autoresponder" id="gf_paypal_delay_autoresponder" value="1" <?php echo rgar($config["meta"], 'delay_autoresponder') ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_delay_autoresponder"><?php _e("Send user notification only when payment is received.", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_delay_user_notification"); ?> </label> </li> <?php $display_post_fields = !empty($form) ? GFCommon::has_post_field($form["fields"]) : false; ?> <li id="paypal_post_action" <?php echo $display_post_fields ? "" : "style='display:none;'"; ?> > <input type="checkbox" name="gf_paypal_delay_post" id="gf_paypal_delay_post" value="1" <?php echo rgar($config["meta"], "delay_post") ? "checked='checked'" : ""; ?> /> <label class="inline" for="gf_paypal_delay_post"><?php _e("Create post only when payment is received.", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_delay_post"); ?> </label> </li> <li id="paypal_post_update_action" <?php echo $display_post_fields && $config["meta"]["type"] == "subscription" ? "" : "style='display:none;'"; ?> > <input type="checkbox" name="gf_paypal_update_post" id="gf_paypal_update_post" value="1" <?php echo rgar($config["meta"], "update_post_action") ? "checked='checked'" : ""; ?> onclick="var action = this.checked ? 'draft' : ''; jQuery('#gf_paypal_update_action').val(action);" /> <label class="inline" for="gf_paypal_update_post"><?php _e("Update Post when subscription is cancelled.", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_update_post"); ?> </label> <select id="gf_paypal_update_action" name="gf_paypal_update_action" onchange="var checked = jQuery(this).val() ? 'checked' : false; jQuery('#gf_paypal_update_post').attr('checked', checked);"> <option value=""></option> <option value="draft" <?php echo rgar($config["meta"], "update_post_action") == "draft" ? "selected='selected'" : ""; ?> ><?php _e("Mark Post as Draft", "gravityformspaypal"); ?> </option> <option value="delete" <?php echo rgar($config["meta"], "update_post_action") == "delete" ? "selected='selected'" : ""; ?> ><?php _e("Delete Post", "gravityformspaypal"); ?> </option> </select> </li> <?php do_action("gform_paypal_action_fields", $config, $form); ?> </ul> </div> <div class="margin_vertical_10" id="gf_paypal_notifications" <?php echo !isset($form["notifications"]) ? "style='display:none;'" : ""; ?> > <label class="left_header"><?php _e("Notifications", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_notifications"); ?> </label> <?php $has_delayed_notifications = rgar($config['meta'], 'delay_notifications') || rgar($config['meta'], 'delay_notification') || rgar($config['meta'], 'delay_autoresponder'); ?> <div style="overflow:hidden;"> <input type="checkbox" name="gf_paypal_delay_notifications" id="gf_paypal_delay_notifications" value="1" onclick="ToggleNotifications();" <?php checked("1", $has_delayed_notifications); ?> /> <label class="inline" for="gf_paypal_delay_notifications"><?php _e("Send notifications only when payment is received.", "gravityformspaypal"); ?> </label> <ul id="gf_paypal_notification_container" style="padding-left:20px; <?php echo $has_delayed_notifications ? "" : "display:none;"; ?> "> <?php if (!empty($form) && is_array($form["notifications"])) { $selected_notifications = self::get_selected_notifications($config, $form); foreach ($form["notifications"] as $notification) { ?> <li class="gf_paypal_notification"> <input type="checkbox" name="gf_paypal_selected_notifications[]" id="gf_paypal_selected_notifications" value="<?php echo $notification["id"]; ?> " <?php checked(true, in_array($notification["id"], $selected_notifications)); ?> /> <label class="inline" for="gf_paypal_selected_notifications"><?php echo $notification["name"]; ?> </label> </li> <?php } } ?> </ul> </div> </div> <?php do_action("gform_paypal_add_option_group", $config, $form); ?> <div id="gf_paypal_conditional_section" valign="top" class="margin_vertical_10"> <label for="gf_paypal_conditional_optin" class="left_header"><?php _e("PayPal Condition", "gravityformspaypal"); ?> <?php gform_tooltip("paypal_conditional"); ?> </label> <div id="gf_paypal_conditional_option"> <table cellspacing="0" cellpadding="0"> <tr> <td> <input type="checkbox" id="gf_paypal_conditional_enabled" name="gf_paypal_conditional_enabled" value="1" onclick="if(this.checked){jQuery('#gf_paypal_conditional_container').fadeIn('fast');} else{ jQuery('#gf_paypal_conditional_container').fadeOut('fast'); }" <?php echo rgar($config['meta'], 'paypal_conditional_enabled') ? "checked='checked'" : ""; ?> /> <label for="gf_paypal_conditional_enable"><?php _e("Enable", "gravityformspaypal"); ?> </label> </td> </tr> <tr> <td> <div id="gf_paypal_conditional_container" <?php echo !rgar($config['meta'], 'paypal_conditional_enabled') ? "style='display:none'" : ""; ?> > <div id="gf_paypal_conditional_fields" style="display:none"> <?php _e("Send to PayPal if ", "gravityformspaypal"); ?> <select id="gf_paypal_conditional_field_id" name="gf_paypal_conditional_field_id" class="optin_select" onchange='jQuery("#gf_paypal_conditional_value_container").html(GetFieldValues(jQuery(this).val(), "", 20));'> </select> <select id="gf_paypal_conditional_operator" name="gf_paypal_conditional_operator"> <option value="is" <?php echo rgar($config['meta'], 'paypal_conditional_operator') == "is" ? "selected='selected'" : ""; ?> ><?php _e("is", "gravityformspaypal"); ?> </option> <option value="isnot" <?php echo rgar($config['meta'], 'paypal_conditional_operator') == "isnot" ? "selected='selected'" : ""; ?> ><?php _e("is not", "gravityformspaypal"); ?> </option> <option value=">" <?php echo rgar($config['meta'], 'paypal_conditional_operator') == ">" ? "selected='selected'" : ""; ?> ><?php _e("greater than", "gravityformspaypal"); ?> </option> <option value="<" <?php echo rgar($config['meta'], 'paypal_conditional_operator') == "<" ? "selected='selected'" : ""; ?> ><?php _e("less than", "gravityformspaypal"); ?> </option> <option value="contains" <?php echo rgar($config['meta'], 'paypal_conditional_operator') == "contains" ? "selected='selected'" : ""; ?> ><?php _e("contains", "gravityformspaypal"); ?> </option> <option value="starts_with" <?php echo rgar($config['meta'], 'paypal_conditional_operator') == "starts_with" ? "selected='selected'" : ""; ?> ><?php _e("starts with", "gravityformspaypal"); ?> </option> <option value="ends_with" <?php echo rgar($config['meta'], 'paypal_conditional_operator') == "ends_with" ? "selected='selected'" : ""; ?> ><?php _e("ends with", "gravityformspaypal"); ?> </option> </select> <div id="gf_paypal_conditional_value_container" name="gf_paypal_conditional_value_container" style="display:inline;"></div> </div> <div id="gf_paypal_conditional_message" style="display:none"> <?php _e("To create a registration condition, your form must have a field supported by conditional logic.", "gravityform"); ?> </div> </div> </td> </tr> </table> </div> </div> <!-- / paypal conditional --> <div id="paypal_submit_container" class="margin_vertical_30"> <input type="submit" name="gf_paypal_submit" value="<?php echo empty($id) ? __(" Save ", "gravityformspaypal") : __("Update", "gravityformspaypal"); ?> " class="button-primary"/> <input type="button" value="<?php _e("Cancel", "gravityformspaypal"); ?> " class="button" onclick="javascript:document.location='admin.php?page=gf_paypal'" /> </div> </div> </form> </div> <script type="text/javascript"> jQuery(document).ready(function(){ SetPeriodNumber('#gf_paypal_billing_cycle_number', jQuery("#gf_paypal_billing_cycle_type").val()); SetPeriodNumber('#gf_paypal_trial_period_number', jQuery("#gf_paypal_trial_period_type").val()); }); function SelectType(type){ jQuery("#paypal_field_group").slideUp(); jQuery("#paypal_field_group input[type=\"text\"], #paypal_field_group select").val(""); jQuery("#gf_paypal_trial_period_type, #gf_paypal_billing_cycle_type").val("M"); jQuery("#paypal_field_group input:checked").attr("checked", false); if(type){ jQuery("#paypal_form_container").slideDown(); jQuery("#gf_paypal_form").val(""); } else{ jQuery("#paypal_form_container").slideUp(); } } function SelectForm(type, formId, settingId){ if(!formId){ jQuery("#paypal_field_group").slideUp(); return; } jQuery("#paypal_wait").show(); jQuery("#paypal_field_group").slideUp(); var mysack = new sack(ajaxurl); mysack.execute = 1; mysack.method = 'POST'; mysack.setVar( "action", "gf_select_paypal_form" ); mysack.setVar( "gf_select_paypal_form", "<?php echo wp_create_nonce("gf_select_paypal_form"); ?> " ); mysack.setVar( "type", type); mysack.setVar( "form_id", formId); mysack.setVar( "setting_id", settingId); mysack.onError = function() {jQuery("#paypal_wait").hide(); alert('<?php _e("Ajax error while selecting a form", "gravityformspaypal"); ?> ' )}; mysack.runAJAX(); return true; } function EndSelectForm(form_meta, customer_fields, recurring_amount_options){ //setting global form object form = form_meta; var type = jQuery("#gf_paypal_type").val(); jQuery(".gf_paypal_invalid_form").hide(); if( (type == "product" || type =="subscription") && GetFieldsByType(["product"]).length == 0){ jQuery("#gf_paypal_invalid_product_form").show(); jQuery("#paypal_wait").hide(); return; } else if(type == "donation" && GetFieldsByType(["product", "donation"]).length == 0){ jQuery("#gf_paypal_invalid_donation_form").show(); jQuery("#paypal_wait").hide(); return; } jQuery(".paypal_field_container").hide(); jQuery("#paypal_customer_fields").html(customer_fields); jQuery("#gf_paypal_recurring_amount").html(recurring_amount_options); //displaying delayed post creation setting if current form has a post field var post_fields = GetFieldsByType(["post_title", "post_content", "post_excerpt", "post_category", "post_custom_field", "post_image", "post_tag"]); if(post_fields.length > 0){ jQuery("#paypal_post_action").show(); } else{ jQuery("#gf_paypal_delay_post").attr("checked", false); jQuery("#paypal_post_action").hide(); } if(type == "subscription" && post_fields.length > 0){ jQuery("#paypal_post_update_action").show(); } else{ jQuery("#gf_paypal_update_post").attr("checked", false); jQuery("#paypal_post_update_action").hide(); } SetPeriodNumber('#gf_paypal_billing_cycle_number', jQuery("#gf_paypal_billing_cycle_type").val()); SetPeriodNumber('#gf_paypal_trial_period_number', jQuery("#gf_paypal_trial_period_type").val()); //Calling callback functions jQuery(document).trigger('paypalFormSelected', [form]); jQuery("#gf_paypal_conditional_enabled").attr('checked', false); SetPayPalCondition("",""); if(form["notifications"]){ jQuery("#gf_paypal_notifications").show(); jQuery("#paypal_delay_autoresponder, #paypal_delay_notification").hide(); } else{ jQuery("#paypal_delay_autoresponder, #paypal_delay_notification").show(); jQuery("#gf_paypal_notifications").hide(); } jQuery("#paypal_field_container_" + type).show(); jQuery("#paypal_field_group").slideDown(); jQuery("#paypal_wait").hide(); } function SetPeriodNumber(element, type){ var prev = jQuery(element).val(); var min = 1; var max = 0; switch(type){ case "D" : max = 100; break; case "W" : max = 52; break; case "M" : max = 12; break; case "Y" : max = 5; break; } var str=""; for(var i=min; i<=max; i++){ var selected = prev == i ? "selected='selected'" : ""; str += "<option value='" + i + "' " + selected + ">" + i + "</option>"; } jQuery(element).html(str); } function GetFieldsByType(types){ var fields = new Array(); for(var i=0; i<form["fields"].length; i++){ if(IndexOf(types, form["fields"][i]["type"]) >= 0) fields.push(form["fields"][i]); } return fields; } function IndexOf(ary, item){ for(var i=0; i<ary.length; i++) if(ary[i] == item) return i; return -1; } </script> <script type="text/javascript"> // Paypal Conditional Functions <?php if (!empty($config["form_id"])) { ?> // initilize form object form = <?php echo GFCommon::json_encode($form); ?> ; // initializing registration condition drop downs jQuery(document).ready(function(){ var selectedField = "<?php echo str_replace('"', '\\"', $config["meta"]["paypal_conditional_field_id"]); ?> "; var selectedValue = "<?php echo str_replace('"', '\\"', $config["meta"]["paypal_conditional_value"]); ?> "; SetPayPalCondition(selectedField, selectedValue); }); <?php } ?> function SetPayPalCondition(selectedField, selectedValue){ // load form fields jQuery("#gf_paypal_conditional_field_id").html(GetSelectableFields(selectedField, 20)); var optinConditionField = jQuery("#gf_paypal_conditional_field_id").val(); var checked = jQuery("#gf_paypal_conditional_enabled").attr('checked'); if(optinConditionField){ jQuery("#gf_paypal_conditional_message").hide(); jQuery("#gf_paypal_conditional_fields").show(); jQuery("#gf_paypal_conditional_value_container").html(GetFieldValues(optinConditionField, selectedValue, 20)); jQuery("#gf_paypal_conditional_value").val(selectedValue); } else{ jQuery("#gf_paypal_conditional_message").show(); jQuery("#gf_paypal_conditional_fields").hide(); } if(!checked) jQuery("#gf_paypal_conditional_container").hide(); } function GetFieldValues(fieldId, selectedValue, labelMaxCharacters){ if(!fieldId) return ""; var str = ""; var field = GetFieldById(fieldId); if(!field) return ""; var isAnySelected = false; if(field["type"] == "post_category" && field["displayAllCategories"]){ str += '<?php $dd = wp_dropdown_categories(array("class" => "optin_select", "orderby" => "name", "id" => "gf_paypal_conditional_value", "name" => "gf_paypal_conditional_value", "hierarchical" => true, "hide_empty" => 0, "echo" => false)); echo str_replace("\n", "", str_replace("'", "\\'", $dd)); ?> '; } else if(field.choices){ str += '<select id="gf_paypal_conditional_value" name="gf_paypal_conditional_value" class="optin_select">' for(var i=0; i<field.choices.length; i++){ var fieldValue = field.choices[i].value ? field.choices[i].value : field.choices[i].text; var isSelected = fieldValue == selectedValue; var selected = isSelected ? "selected='selected'" : ""; if(isSelected) isAnySelected = true; str += "<option value='" + fieldValue.replace(/'/g, "'") + "' " + selected + ">" + TruncateMiddle(field.choices[i].text, labelMaxCharacters) + "</option>"; } if(!isAnySelected && selectedValue){ str += "<option value='" + selectedValue.replace(/'/g, "'") + "' selected='selected'>" + TruncateMiddle(selectedValue, labelMaxCharacters) + "</option>"; } str += "</select>"; } else { selectedValue = selectedValue ? selectedValue.replace(/'/g, "'") : ""; //create a text field for fields that don't have choices (i.e text, textarea, number, email, etc...) str += "<input type='text' placeholder='<?php _e("Enter value", "gravityforms"); ?> ' id='gf_paypal_conditional_value' name='gf_paypal_conditional_value' value='" + selectedValue.replace(/'/g, "'") + "'>"; } return str; } function GetFieldById(fieldId){ for(var i=0; i<form.fields.length; i++){ if(form.fields[i].id == fieldId) return form.fields[i]; } return null; } function TruncateMiddle(text, maxCharacters){ if(!text) return ""; if(text.length <= maxCharacters) return text; var middle = parseInt(maxCharacters / 2); return text.substr(0, middle) + "..." + text.substr(text.length - middle, middle); } function GetSelectableFields(selectedFieldId, labelMaxCharacters){ var str = ""; var inputType; for(var i=0; i<form.fields.length; i++){ fieldLabel = form.fields[i].adminLabel ? form.fields[i].adminLabel : form.fields[i].label; inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type; if (IsConditionalLogicField(form.fields[i])) { var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : ""; str += "<option value='" + form.fields[i].id + "' " + selected + ">" + TruncateMiddle(fieldLabel, labelMaxCharacters) + "</option>"; } } return str; } function IsConditionalLogicField(field){ inputType = field.inputType ? field.inputType : field.type; var supported_fields = ["checkbox", "radio", "select", "text", "website", "textarea", "email", "hidden", "number", "phone", "multiselect", "post_title", "post_tags", "post_custom_field", "post_content", "post_excerpt"]; var index = jQuery.inArray(inputType, supported_fields); return index >= 0; } </script> <?php }
private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name = '', $message_format = 'html', $attachments = '') { global $phpmailer; $to = str_replace(' ', '', $to); $bcc = str_replace(' ', '', $bcc); $error = false; if (!GFCommon::is_valid_email($from)) { $from = get_bloginfo('admin_email'); } if (!GFCommon::is_valid_email_list($to)) { $error = new WP_Error('invalid_to', 'Cannot send email because the TO address is invalid.'); } else { if (empty($subject) && empty($message)) { $error = new WP_Error('missing_subject_and_message', 'Cannot send email because there is no SUBJECT and no MESSAGE.'); } else { if (!GFCommon::is_valid_email($from)) { $error = new WP_Error('invalid_from', 'Cannot send email because the FROM address is invalid.'); } } } if (is_wp_error($error)) { GFCommon::log_error('GFCommon::send_email(): ' . $error->get_error_message()); GFCommon::log_error(print_r(compact('to', 'subject', 'message'), true)); /** * Fires when an email from Gravity Forms has failed to send * * @param string $error The Error message returned after the email fails to send */ do_action('gform_send_email_failed', $error, compact('from', 'to', 'bcc', 'reply_to', 'subject', 'message', 'from_name', 'message_format', 'attachments')); return; } $content_type = $message_format == 'html' ? 'text/html' : 'text/plain'; $name = empty($from_name) ? $from : $from_name; $headers = array(); $headers['From'] = "From: \"" . wp_strip_all_tags($name, true) . "\" <{$from}>"; if (GFCommon::is_valid_email_list($reply_to)) { $headers['Reply-To'] = "Reply-To: {$reply_to}"; } if (GFCommon::is_valid_email_list($bcc)) { $headers['Bcc'] = "Bcc: {$bcc}"; } $headers['Content-type'] = "Content-type: {$content_type}; charset=" . get_option('blog_charset'); $abort_email = false; extract(apply_filters('gform_pre_send_email', compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), $message_format)); $is_success = false; if (!$abort_email) { GFCommon::log_debug('GFCommon::send_email(): Sending email via wp_mail().'); GFCommon::log_debug(print_r(compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), true)); $is_success = wp_mail($to, $subject, $message, $headers, $attachments); $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success; GFCommon::log_debug("GFCommon::send_email(): Result from wp_mail(): {$result}"); if (!is_wp_error($is_success) && $is_success) { GFCommon::log_debug('GFCommon::send_email(): Mail was passed from WordPress to the mail server.'); } else { GFCommon::log_error('GFCommon::send_email(): The mail message was passed off to WordPress for processing, but WordPress was unable to send the message.'); } if (has_filter('phpmailer_init')) { GFCommon::log_debug(__METHOD__ . '(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.'); } if (!empty($phpmailer->ErrorInfo)) { GFCommon::log_debug(__METHOD__ . '(): PHPMailer class returned an error message: ' . $phpmailer->ErrorInfo); } } else { GFCommon::log_debug('GFCommon::send_email(): Aborting. The gform_pre_send_email hook was used to set the abort_email parameter to true.'); } self::add_emails_sent(); /** * Fires after Gravity Forms has sent an email * * @param bool $is_success Check if the email was successfully sent * @param string $to The user Email to send to * @param string $subject The Subject of the email sent out * @param string $message The Message sent with a notification, alert, etc. * @param string $headers The email headers (the content-type and charset) * @param string $attachments The email attachments sent along * @param string $message_fomrat The Message format (HTML/Plain Text) * @param string $from Who the email is coming from * @param string $form_name The Name of the user who is associated with the from email * @param string $bcc The blind carbon copy which is an extra email that won't appear in the email header * @param string $reply_to A header that allows you to reply to another email */ do_action('gform_after_email', $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to); }
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; 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; case "radio": case "select": return GFCommon::selection_display($value, $field, $currency, $use_text); break; case "singleproduct": if (is_array($value)) { $product_name = trim($value[$field["id"] . ".1"]); $price = trim($value[$field["id"] . ".2"]); $quantity = trim($value[$field["id"] . ".3"]); $product = $product_name . ", " . __("Qty: ", "gravityforms") . $quantity . ", " . __("Price: ", "gravityforms") . $price; return $product; } else { return ""; } break; case "singleshipping": case "donation": case "total": case "price": return GFCommon::to_money($value, $currency); default: return nl2br($value); break; } }
private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name = '', $message_format = 'html', $attachments = '') { global $phpmailer; $to = str_replace(' ', '', $to); $bcc = str_replace(' ', '', $bcc); $error = false; if (!GFCommon::is_valid_email($from)) { $from = get_bloginfo('admin_email'); } if (!GFCommon::is_valid_email_list($to)) { $error = new WP_Error('invalid_to', 'Cannot send email because the TO address is invalid.'); } else { if (empty($subject) && empty($message)) { $error = new WP_Error('missing_subject_and_message', 'Cannot send email because there is no SUBJECT and no MESSAGE.'); } else { if (!GFCommon::is_valid_email($from)) { $error = new WP_Error('invalid_from', 'Cannot send email because the FROM address is invalid.'); } } } if (is_wp_error($error)) { GFCommon::log_error('GFCommon::send_email(): ' . $error->get_error_message()); GFCommon::log_error(print_r(compact('to', 'subject', 'message'), true)); do_action('gform_send_email_failed', $error, compact('from', 'to', 'bcc', 'reply_to', 'subject', 'message', 'from_name', 'message_format', 'attachments')); return; } $content_type = $message_format == 'html' ? 'text/html' : 'text/plain'; $name = empty($from_name) ? $from : $from_name; $headers = array(); $headers['From'] = "From: \"" . wp_strip_all_tags($name, true) . "\" <{$from}>"; if (GFCommon::is_valid_email_list($reply_to)) { $headers['Reply-To'] = "Reply-To: {$reply_to}"; } if (GFCommon::is_valid_email_list($bcc)) { $headers['Bcc'] = "Bcc: {$bcc}"; } $headers['Content-type'] = "Content-type: {$content_type}; charset=" . get_option('blog_charset'); $abort_email = false; extract(apply_filters('gform_pre_send_email', compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), $message_format)); $is_success = false; if (!$abort_email) { GFCommon::log_debug('GFCommon::send_email(): Sending email via wp_mail().'); GFCommon::log_debug(print_r(compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), true)); $is_success = wp_mail($to, $subject, $message, $headers, $attachments); $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success; GFCommon::log_debug("GFCommon::send_email(): Result from wp_mail(): {$result}"); if (!is_wp_error($is_success) && $is_success) { GFCommon::log_debug('GFCommon::send_email(): Mail was passed from WordPress to the mail server.'); } else { GFCommon::log_error('GFCommon::send_email(): The mail message was passed off to WordPress for processing, but WordPress was unable to send the message.'); } if (has_filter('phpmailer_init')) { GFCommon::log_debug(__METHOD__ . '(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.'); } if (!empty($phpmailer->ErrorInfo)) { GFCommon::log_debug(__METHOD__ . '(): PHPMailer class returned an error message: ' . $phpmailer->ErrorInfo); } } else { GFCommon::log_debug('GFCommon::send_email(): Aborting. The gform_pre_send_email hook was used to set the abort_email parameter to true.'); } self::add_emails_sent(); do_action('gform_after_email', $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to); }
private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name = '', $message_format = 'html', $attachments = '', $entry = false, $notification = false) { global $phpmailer; $to = str_replace(' ', '', $to); $bcc = str_replace(' ', '', $bcc); $error = false; if (!GFCommon::is_valid_email($from)) { $from = get_bloginfo('admin_email'); } if (!GFCommon::is_valid_email_list($to)) { $error = new WP_Error('invalid_to', 'Cannot send email because the TO address is invalid.'); } else { if (empty($subject) && empty($message)) { $error = new WP_Error('missing_subject_and_message', 'Cannot send email because there is no SUBJECT and no MESSAGE.'); } else { if (!GFCommon::is_valid_email($from)) { $error = new WP_Error('invalid_from', 'Cannot send email because the FROM address is invalid.'); } } } if (is_wp_error($error)) { GFCommon::log_error('GFCommon::send_email(): ' . $error->get_error_message()); GFCommon::log_error(print_r(compact('to', 'subject', 'message'), true)); /** * Fires when an email from Gravity Forms has failed to send * * @since 1.8.10 * * @param string $error The Error message returned after the email fails to send * @param array $details The details of the message that failed * @param array $entry The Entry object * */ do_action('gform_send_email_failed', $error, compact('from', 'to', 'bcc', 'reply_to', 'subject', 'message', 'from_name', 'message_format', 'attachments'), $entry); return; } $content_type = $message_format == 'html' ? 'text/html' : 'text/plain'; $name = empty($from_name) ? $from : $from_name; $headers = array(); $headers['From'] = "From: \"" . wp_strip_all_tags($name, true) . "\" <{$from}>"; if (GFCommon::is_valid_email_list($reply_to)) { $headers['Reply-To'] = "Reply-To: {$reply_to}"; } if (GFCommon::is_valid_email_list($bcc)) { $headers['Bcc'] = "Bcc: {$bcc}"; } $headers['Content-type'] = "Content-type: {$content_type}; charset=" . get_option('blog_charset'); $abort_email = false; extract(apply_filters('gform_pre_send_email', compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), $message_format, $notification)); $is_success = false; if (!$abort_email) { GFCommon::log_debug('GFCommon::send_email(): Sending email via wp_mail().'); GFCommon::log_debug(print_r(compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), true)); $is_success = wp_mail($to, $subject, $message, $headers, $attachments); $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success; GFCommon::log_debug("GFCommon::send_email(): Result from wp_mail(): {$result}"); if (!is_wp_error($is_success) && $is_success) { GFCommon::log_debug('GFCommon::send_email(): Mail was passed from WordPress to the mail server.'); } else { GFCommon::log_error('GFCommon::send_email(): The mail message was passed off to WordPress for processing, but WordPress was unable to send the message.'); } if (has_filter('phpmailer_init')) { GFCommon::log_debug(__METHOD__ . '(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.'); } if (!empty($phpmailer->ErrorInfo)) { GFCommon::log_debug(__METHOD__ . '(): PHPMailer class returned an error message: ' . $phpmailer->ErrorInfo); } } else { GFCommon::log_debug('GFCommon::send_email(): Aborting. The gform_pre_send_email hook was used to set the abort_email parameter to true.'); } self::add_emails_sent(); /** * Fires after an email is sent * * @param bool $is_success True is successfully sent. False if failed * @param string $to Recipient address * @param string $subject Subject line * @param string $message Message body * @param string $headers Email headers * @param string $attachments Email attachments * @param string $message_format Format of the email. Ex: text, html * @param string $from Address of the sender * @param string $from_name Displayed name of the sender * @param string $bcc BCC recipients * @param string $reply_to Reply-to address * @param array $entry Entry object associated with the sent email * */ do_action('gform_after_email', $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to, $entry); }
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; } } } if (empty($items)) { return ''; } else { if ($format == 'text') { return substr($items, 0, strlen($items) - 2); //removing last comma } else { return '<ul class="bulleted">' . $items . '</ul>'; } } } else { return $value; } break; case 'post_image': $ary = explode('|:|', $value); $url = count($ary) > 0 ? $ary[0] : ''; $title = count($ary) > 1 ? $ary[1] : ''; $caption = count($ary) > 2 ? $ary[2] : ''; $description = count($ary) > 3 ? $ary[3] : ''; if (!empty($url)) { $url = str_replace(' ', '%20', $url); switch ($format) { case 'text': $value = $url; $value .= !empty($title) ? '\\n\\n' . $field['label'] . ' (' . __('Title', 'gravityforms') . '): ' . $title : ''; $value .= !empty($caption) ? '\\n\\n' . $field['label'] . ' (' . __('Caption', 'gravityforms') . '): ' . $caption : ''; $value .= !empty($description) ? '\\n\\n' . $field['label'] . ' (' . __('Description', 'gravityforms') . '): ' . $description : ''; break; default: $path = str_replace(site_url() . '/', ABSPATH, $url); $value = "<a href='{$url}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$path}' width='100' /></a>"; $value .= !empty($title) ? "<div>Title: {$title}</div>" : ""; $value .= !empty($caption) ? "<div>Caption: {$caption}</div>" : ""; $value .= !empty($description) ? "<div>Description: {$description}</div>" : ""; break; } } return $value; case 'fileupload': $output = ''; $output_arr = array(); if (!empty($value)) { $output .= '<ul>'; $file_paths = rgar($field, 'multipleFiles') ? json_decode($value) : array($value); foreach ($file_paths as $file_path) { $info = pathinfo($file_path); $file_path = esc_attr(str_replace(' ', '%20', $file_path)); $output_arr[] = '<li><a href="' . $file_path . '" target="_blank" title="' . __('Click to view', 'gravityforms') . '">' . $info['basename'] . '</a></li>'; } $output .= join(PHP_EOL, $output_arr); $output .= '</ul>'; } return $output; break; case 'date': return GFCommon::date_display($value, rgar($field, 'dateFormat')); break; case 'radio': case 'select': return GFCommon::selection_display($value, $field, $currency, true); break; case 'multiselect': if (empty($value) || $format == 'text') { return $value; } if (!is_array($value)) { $value = explode(',', $value); } $items = ''; foreach ($value as $item) { $items .= '<li>' . GFCommon::selection_display($item, $field, $currency, true) . '</li>'; } return '<ul class="bulleted">' . $items . '</ul>'; break; case 'calculation': case 'singleproduct': if (is_array($value)) { $product_name = trim($value[$field['id'] . '.1']); $price = trim($value[$field['id'] . '.2']); $quantity = trim($value[$field['id'] . '.3']); $product = $product_name . ', ' . __('Qty: ', 'gravityforms') . $quantity . ', ' . __('Price: ', 'gravityforms') . $price; return $product; } else { return ''; } break; case 'number': return GFCommon::format_number($value, rgar($field, 'numberFormat')); break; case 'singleshipping': case 'donation': case 'total': case 'price': return GFCommon::to_money($value, $currency); case 'list': if (empty($value)) { return ''; } $value = unserialize($value); $has_columns = is_array($value[0]); if (!$has_columns) { $items = ''; foreach ($value as $key => $item) { if (!empty($item)) { switch ($format) { case 'text': $items .= $item . ', '; break; case 'url': $items .= $item . ','; break; default: if ($media == 'email') { $items .= '<li>' . htmlspecialchars($item) . '</li>'; } else { $items .= '<li>' . htmlspecialchars($item) . '</li>'; } break; } } } if (empty($items)) { return ''; } else { if ($format == 'text') { return substr($items, 0, strlen($items) - 2); //removing last comma } else { if ($format == 'url') { return substr($items, 0, strlen($items) - 1); //removing last comma } else { return '<ul class="bulleted">' . $items . '</ul>'; } } } } else { if (is_array($value)) { $columns = array_keys($value[0]); $list = ''; switch ($format) { case 'text': $is_first_row = true; foreach ($value as $item) { if (!$is_first_row) { $list .= '\\n\\n' . $field['label'] . ': '; } $list .= implode(',', array_values($item)); $is_first_row = false; } break; case 'url': foreach ($value as $item) { $list .= implode('|', array_values($item)) . ','; } if (!empty($list)) { $list = substr($list, 0, strlen($list) - 1); } break; default: if ($media == 'email') { $list = '<table autosize="1" class="gfield_list" style="border-top: 1px solid #DFDFDF; border-left: 1px solid #DFDFDF; border-spacing: 0; padding: 0; margin: 2px 0 6px; width: 100%"><thead><tr>'; //reading columns from entry data foreach ($columns as $column) { $list .= '<th style="background-image: none; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; padding: 6px 10px; font-family: sans-serif; font-size: 12px; font-weight: bold; background-color: #F1F1F1; color:#333; text-align:left">' . esc_html($column) . '</th>'; } $list .= '</tr></thead>'; $list .= '<tbody style="background-color: #F9F9F9">'; foreach ($value as $item) { $list .= '<tr>'; foreach ($columns as $column) { $val = rgar($item, $column); $list .= '<td style="padding: 6px 10px; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; border-top: 1px solid #FFF; font-family: sans-serif; font-size:12px;">{$val}</td>'; } $list .= '</tr>'; } $list .= '</tbody></table>'; } else { $list = '<table autosize="1" class="gfield_list"><thead><tr>'; //reading columns from entry data foreach ($columns as $column) { $list .= '<th>' . esc_html($column) . '</th>'; } $list .= '</tr></thead>'; $list .= '<tbody>'; foreach ($value as $item) { $list .= '<tr>'; foreach ($columns as $column) { $val = rgar($item, $column); $list .= '<td>' . htmlspecialchars($val) . '</td>'; } $list .= '</tr>'; } $list .= '</tbody></table>'; } break; } return $list; } } return ''; break; default: if (!is_array($value)) { return nl2br($value); } break; } }
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; } 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).", "gravityforms"), $format == "mdy" ? "mm/dd/yyyy" : "dd/mm/yyyy") : $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 (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; } } //finding second number $second = 0; for ($second = 0; $second < 10; $second++) { if ($captcha_obj->check($prefixes[2], $second)) { break; } } //if it is a +, perform the sum if ($captcha_obj->check($prefixes[1], "+")) { $result = $first + $second; } else { $result = $first - $second; } if (intval($result) != intval($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; default: 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(rgget("extension", $info)); 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; case "singleproduct": $quantity = rgget($field["id"] . "3", $value); if (empty($quantity)) { $quantity = 0; } if (!is_numeric($quantity) || intval($quantity) != floatval($quantity)) { $field["failed_validation"] = true; $field["validation_message"] = __("Please enter a valid quantity", "gravityforms"); $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; }
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"); } } } break; case "price": if (!class_exists("RGCurrency")) { require_once "currency.php"; } $donation = GFCommon::to_number($value); if (!rgblank($value) && ($donation === false || $donation < 0)) { $field["failed_validation"] = true; $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid amount.", "gravityforms") : $field["errorMessage"]; } break; case "number": // the POST value has already been converted from currency or decimal_comma to decimal_dot and then cleaned in get_field_value() $value = GFCommon::maybe_add_leading_zero($value); $raw_value = $_POST["input_" . $field["id"]]; //Raw value will be tested against the is_numeric() function to make sure it is in the right format. $requires_valid_number = !rgblank($raw_value) && !GFCommon::has_field_calculation($field); $is_valid_number = self::validate_range($field, $value) && GFCommon::is_numeric($raw_value, $field["numberFormat"]); if ($requires_valid_number && !$is_valid_number) { $field["failed_validation"] = true; $field["validation_message"] = empty($field["errorMessage"]) ? GFCommon::get_range_message($field) : $field["errorMessage"]; } else { if ($field['type'] == 'quantity') { if (intval($value) != $value) { $field['failed_validation'] = true; $field['validation_message'] = empty($field['errorMessage']) ? __('Please enter a valid quantity. Quantity cannot contain decimals.', 'gravityforms') : $field['errorMessage']; } else { if (!empty($value) && (!is_numeric($value) || intval($value) != floatval($value) || intval($value) < 0)) { $field['failed_validation'] = true; $field['validation_message'] = empty($field['errorMessage']) ? __('Please enter a valid quantity', 'gravityforms') : $field['errorMessage']; } } } } break; case "phone": $regex = '/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/'; if ($field["phoneFormat"] == "standard" && $value !== "" && $value !== 0 && !preg_match($regex, $value)) { $field["failed_validation"] = true; if (!empty($field["errorMessage"])) { $field["validation_message"] = $field["errorMessage"]; } } break; case "date": if (is_array($value) && rgempty(0, $value) && rgempty(1, $value) && rgempty(2, $value)) { $value = null; } if (!empty($value)) { $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"]; $date = GFCommon::parse_date($value, $format); if (empty($date) || !GFFormDisplay::checkdate($date["month"], $date["day"], $date["year"])) { $field["failed_validation"] = true; $format_name = ""; switch ($format) { case "mdy": $format_name = "mm/dd/yyyy"; break; case "dmy": $format_name = "dd/mm/yyyy"; 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; }
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; $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; }
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; } }