/** * Get the default date format for a field based on the field ID and the time format setting * * @since 1.16.4 * @param string $date_format The Gravity Forms date format for the field. Default: "mdy" * @param int $field_id The ID of the field. Used to figure out full date/day/month/year * * @return string PHP date format for the date */ public static function date_display($value = '', $date_format = 'mdy', $field_id = 0) { // Let Gravity Forms figure out, based on the date format, what day/month/year values are. $parsed_date = GFCommon::parse_date($value, $date_format); // Are we displaying an input or the whole field? $field_input_id = gravityview_get_input_id_from_id($field_id); $date_field_output = ''; switch ($field_input_id) { case 1: $date_field_output = rgar($parsed_date, 'day'); break; case 2: $date_field_output = rgar($parsed_date, 'month'); break; case 3: $date_field_output = rgar($parsed_date, 'year'); break; } /** * @filter `gravityview_date_format` Whether to override the Gravity Forms date format with a PHP date format * @see https://codex.wordpress.org/Formatting_Date_and_Time * @param null|string Date Format (default: $field->dateFormat) */ $full_date_format = apply_filters('gravityview_date_format', $date_format); $full_date = GFCommon::date_display($value, $full_date_format); // If the field output is empty, use the full date. // Note: The output might be empty because $parsed_date didn't parse correctly. return '' === $date_field_output ? $full_date : $date_field_output; }
public static function prepare_date($date_format, $value) { $format = empty($date_format) ? 'mdy' : $date_format; $date_info = GFCommon::parse_date($value, $format); if (!empty($date_info) && !GFCommon::is_empty_array($date_info)) { $value = sprintf('%s-%02d-%02d', $date_info['year'], $date_info['month'], $date_info['day']); } else { $value = ''; } return $value; }
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 function get_field_input($form, $value = '', $entry = null) { $picker_value = ''; if (is_array($value)) { // GFCommon::parse_date() takes a numeric array. $value = array_values($value); } else { $picker_value = $value; } $format = empty($this->dateFormat) ? 'mdy' : esc_attr($this->dateFormat); $date_info = GFCommon::parse_date($value, $format); $day_value = esc_attr(rgget('day', $date_info)); $month_value = esc_attr(rgget('month', $date_info)); $year_value = esc_attr(rgget('year', $date_info)); $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $form_id = $form['id']; $id = intval($this->id); $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $size = $this->size; $disabled_text = $is_form_editor ? "disabled='disabled'" : ''; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $size . $class_suffix; $form_sub_label_placement = rgar($form, 'subLabelPlacement'); $field_sub_label_placement = rgar($this, 'subLabelPlacement'); $is_sub_label_above = $field_sub_label_placement == 'above' || empty($field_sub_label_placement) && $form_sub_label_placement == 'above'; $sub_label_class_attribute = $field_sub_label_placement == 'hidden_label' ? "class='hidden_sub_label screen-reader-text'" : ''; $month_input = GFFormsModel::get_input($this, $this->id . '.1'); $day_input = GFFormsModel::get_input($this, $this->id . '.2'); $year_input = GFFormsModel::get_input($this, $this->id . '.3'); $month_sub_label = rgar($month_input, 'customLabel') != '' ? $month_input['customLabel'] : esc_html(_x('MM', 'Abbreviation: Month', 'gravityforms')); $day_sub_label = rgar($day_input, 'customLabel') != '' ? $day_input['customLabel'] : esc_html__('DD', 'gravityforms'); $year_sub_label = rgar($year_input, 'customLabel') != '' ? $year_input['customLabel'] : esc_html__('YYYY', 'gravityforms'); $month_placeholder_attribute = GFCommon::get_input_placeholder_attribute($month_input); $day_placeholder_attribute = GFCommon::get_input_placeholder_attribute($day_input); $year_placeholder_attribute = GFCommon::get_input_placeholder_attribute($year_input); $month_placeholder_value = GFCommon::get_input_placeholder_value($month_input); $day_placeholder_value = GFCommon::get_input_placeholder_value($day_input); $year_placeholder_value = GFCommon::get_input_placeholder_value($year_input); $date_picker_placeholder = $this->get_field_placeholder_attribute(); $is_html5 = RGFormsModel::is_html5_enabled(); $date_input_type = $is_html5 ? 'number' : 'text'; $month_html5_attributes = $is_html5 ? "min='1' max='12' step='1'" : ''; $day_html5_attributes = $is_html5 ? "min='1' max='31' step='1'" : ''; $year_min = apply_filters('gform_date_min_year', '1920', $form, $this); $year_max = apply_filters('gform_date_max_year', date('Y') + 1, $form, $this); $year_min_attribute = $is_html5 && is_numeric($year_min) ? "min='{$year_min}'" : ''; $year_max_attribute = $is_html5 && is_numeric($year_max) ? "max='{$year_max}'" : ''; $year_step_attribute = $is_html5 ? "step='1'" : ''; $field_position = substr($format, 0, 3); if ($is_form_editor) { $datepicker_display = in_array($this->dateType, array('datefield', 'datedropdown')) ? 'none' : 'inline'; $datefield_display = $this->dateType == 'datefield' ? 'inline' : 'none'; $dropdown_display = $this->dateType == 'datedropdown' ? 'inline' : 'none'; $icon_display = $this->calendarIconType == 'calendar' ? 'inline' : 'none'; if ($is_sub_label_above) { $month_field = "<div class='gfield_date_month ginput_date' id='gfield_input_date_month' style='display:{$datefield_display}'>\n <label for='{$field_id}_1' {$sub_label_class_attribute}>{$month_sub_label}</label>\n <input id='{$field_id}_1' name='ginput_month' type='text' {$month_placeholder_attribute} {$disabled_text} value='{$month_value}'/>\n </div>"; $day_field = "<div class='gfield_date_day ginput_date' id='gfield_input_date_day' style='display:{$datefield_display}'>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$day_sub_label}</label>\n <input id='{$field_id}_2' name='ginput_day' type='text' {$day_placeholder_attribute} {$disabled_text} value='{$day_value}'/>\n </div>"; $year_field = "<div class='gfield_date_year ginput_date' id='gfield_input_date_year' style='display:{$datefield_display}'>\n <label {$sub_label_class_attribute}>{$year_sub_label}</label>\n <input id='{$field_id}_3' type='text' name='text' {$year_placeholder_attribute} {$disabled_text} value='{$year_value}'/>\n </div>"; } else { $month_field = "<div class='gfield_date_month ginput_date' id='gfield_input_date_month' style='display:{$datefield_display}'>\n <input id='{$field_id}_1' name='ginput_month' type='text' {$month_placeholder_attribute} {$disabled_text} value='{$month_value}'/>\n <label for='{$field_id}_1' {$sub_label_class_attribute}>{$month_sub_label}</label>\n </div>"; $day_field = "<div class='gfield_date_day ginput_date' id='gfield_input_date_day' style='display:{$datefield_display}'>\n <input id='{$field_id}_2' name='ginput_day' type='text' {$day_placeholder_attribute} {$disabled_text} value='{$day_value}'/>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$day_sub_label}</label>\n </div>"; $year_field = "<div class='gfield_date_year ginput_date' id='gfield_input_date_year' style='display:{$datefield_display}'>\n <input type='text' id='{$field_id}_3' name='ginput_year' {$year_placeholder_attribute} {$disabled_text} value='{$year_value}'/>\n <label for='{$field_id}_3' {$sub_label_class_attribute}>{$year_sub_label}</label>\n </div>"; } $month_dropdown = "<div class='gfield_date_dropdown_month ginput_date_dropdown' id='gfield_dropdown_date_month' style='display:{$dropdown_display}'>" . $this->get_month_dropdown('', "{$field_id}_1", rgar($date_info, 'month'), '', $disabled_text, $month_placeholder_value) . '</div>'; $day_dropdown = "<div class='gfield_date_dropdown_day ginput_date_dropdown' id='gfield_dropdown_date_day' style='display:{$dropdown_display}'>" . $this->get_day_dropdown('', "{$field_id}_2", rgar($date_info, 'day'), '', $disabled_text, $day_placeholder_value) . '</div>'; $year_dropdown = "<div class='gfield_date_dropdown_year ginput_date_dropdown' id='gfield_dropdown_date_year' style='display:{$dropdown_display}'>" . $this->get_year_dropdown('', "{$field_id}_3", rgar($date_info, 'year'), '', $disabled_text, $year_placeholder_value, $form) . '</div>'; $field_string = "<div class='ginput_container ginput_container_date' id='gfield_input_datepicker' style='display:{$datepicker_display}'><input name='ginput_datepicker' type='text' {$date_picker_placeholder} {$disabled_text} value = '{$picker_value}'/><img src='" . GFCommon::get_base_url() . "/images/calendar.png' id='gfield_input_datepicker_icon' style='display:{$icon_display}'/></div>"; switch ($field_position) { case 'dmy': $date_inputs = $day_field . $month_field . $year_field . $day_dropdown . $month_dropdown . $year_dropdown; break; case 'ymd': $date_inputs = $year_field . $month_field . $day_field . $year_dropdown . $month_dropdown . $day_dropdown; break; default: $date_inputs = $month_field . $day_field . $year_field . $month_dropdown . $day_dropdown . $year_dropdown; break; } $field_string .= "<div id='{$field_id}' class='ginput_container ginput_container_date'>{$date_inputs}</div>"; return $field_string; } else { $date_type = $this->dateType; if (in_array($date_type, array('datefield', 'datedropdown'))) { switch ($field_position) { case 'dmy': $tabindex = $this->get_tabindex(); if ($date_type == 'datedropdown') { $field_str = "<div class='clear-multi'><div class='gfield_date_dropdown_day ginput_container ginput_container_date' id='{$field_id}_2_container'>" . $this->get_day_dropdown("input_{$id}[]", "{$field_id}_2", rgar($date_info, 'day'), $tabindex, $disabled_text, $day_placeholder_value) . '</div>'; $tabindex = $this->get_tabindex(); $field_str .= "<div class='gfield_date_dropdown_month ginput_container ginput_container_date' id='{$field_id}_1_container'>" . $this->get_month_dropdown("input_{$id}[]", "{$field_id}_1", rgar($date_info, 'month'), $tabindex, $disabled_text, $month_placeholder_value) . '</div>'; $tabindex = $this->get_tabindex(); $field_str .= "<div class='gfield_date_dropdown_year ginput_container ginput_container_date' id='{$field_id}_3_container'>" . $this->get_year_dropdown("input_{$id}[]", "{$field_id}_3", rgar($date_info, 'year'), $tabindex, $disabled_text, $year_placeholder_value, $form) . '</div></div>'; } else { $field_str = $is_sub_label_above ? "<div class='clear-multi'>\n <div class='gfield_date_day ginput_container ginput_container_date' id='{$field_id}_2_container'>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$day_sub_label}</label>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_2' value='{$day_value}' {$tabindex} {$disabled_text} {$day_placeholder_attribute} {$day_html5_attributes}/>\n </div>" : "<div class='clear-multi'>\n <div class='gfield_date_day ginput_container ginput_container_date' id='{$field_id}_2_container'>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_2' value='{$day_value}' {$tabindex} {$disabled_text} {$day_placeholder_attribute} {$day_html5_attributes}/>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$day_sub_label}</label>\n </div>"; $tabindex = $this->get_tabindex(); $field_str .= $is_sub_label_above ? "<div class='gfield_date_month ginput_container ginput_container_date' id='{$field_id}_1_container'>\n <label for='{$field_id}_1' {$sub_label_class_attribute}>{$month_sub_label}</label>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_1' value='{$month_value}' {$tabindex} {$disabled_text} {$month_placeholder_attribute} {$month_html5_attributes}/>\n </div>" : "<div class='gfield_date_month ginput_container ginput_container_date' id='{$field_id}_1_container'>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_1' value='{$month_value}' {$tabindex} {$disabled_text} {$month_placeholder_attribute} {$month_html5_attributes}/>\n <label for='{$field_id}_1' {$sub_label_class_attribute}>{$month_sub_label}</label>\n </div>"; $tabindex = $this->get_tabindex(); $field_str .= $is_sub_label_above ? "<div class='gfield_date_year ginput_container ginput_container_date' id='{$field_id}_3_container'>\n <label for='{$field_id}_3' {$sub_label_class_attribute}>{$year_sub_label}</label>\n <input type='{$date_input_type}' maxlength='4' name='input_{$id}[]' id='{$field_id}_3' value='{$year_value}' {$tabindex} {$disabled_text} {$year_placeholder_attribute} {$year_min_attribute} {$year_max_attribute} {$year_step_attribute}/>\n </div>\n </div>" : "<div class='gfield_date_year ginput_container ginput_container_date' id='{$field_id}_3_container'>\n <input type='{$date_input_type}' maxlength='4' name='input_{$id}[]' id='{$field_id}_3' value='{$year_value}' {$tabindex} {$disabled_text} {$year_placeholder_attribute} {$year_min_attribute} {$year_max_attribute} {$year_step_attribute}/>\n <label for='{$field_id}_3' {$sub_label_class_attribute}>{$year_sub_label}</label>\n </div>\n </div>"; } break; case 'ymd': $tabindex = $this->get_tabindex(); if ($date_type == 'datedropdown') { $field_str = "<div class='clear-multi'><div class='gfield_date_dropdown_year ginput_container ginput_container_date' id='{$field_id}_3_container'>" . $this->get_year_dropdown("input_{$id}[]", "{$field_id}_3", rgar($date_info, 'year'), $tabindex, $disabled_text, $year_placeholder_value, $form) . '</div>'; $tabindex = $this->get_tabindex(); $field_str .= "<div class='gfield_date_dropdown_month ginput_container ginput_container_date' id='{$field_id}_1_container'>" . $this->get_month_dropdown("input_{$id}[]", "{$field_id}_1", rgar($date_info, 'month'), $tabindex, $disabled_text, $month_placeholder_value) . '</div>'; $tabindex = $this->get_tabindex(); $field_str .= "<div class='gfield_date_dropdown_day ginput_container ginput_container_date' id='{$field_id}_2_container'>" . $this->get_day_dropdown("input_{$id}[]", "{$field_id}_2", rgar($date_info, 'day'), $tabindex, $disabled_text, $day_placeholder_value) . '</div></div>'; } else { $field_str = $is_sub_label_above ? "<div class='clear-multi'>\n <div class='gfield_date_year ginput_container ginput_container_date' id='{$field_id}_3_container'>\n <label for='{$field_id}_3' {$sub_label_class_attribute}>{$year_sub_label}</label>\n <input type='{$date_input_type}' maxlength='4' name='input_{$id}[]' id='{$field_id}_3' value='{$year_value}' {$tabindex} {$disabled_text} {$year_placeholder_attribute} {$year_min_attribute} {$year_max_attribute} {$year_step_attribute}/>\n </div>" : "<div class='clear-multi'>\n <div class='gfield_date_year ginput_container ginput_container_date' id='{$field_id}_3_container'>\n <input type='{$date_input_type}' maxlength='4' name='input_{$id}[]' id='{$field_id}_3' value='{$year_value}' {$tabindex} {$disabled_text} {$year_placeholder_attribute} {$year_min_attribute} {$year_max_attribute} {$year_step_attribute}/>\n <label for='{$field_id}_3' {$sub_label_class_attribute}>{$year_sub_label}</label>\n </div>"; $tabindex = $this->get_tabindex(); $field_str .= $is_sub_label_above ? "<div class='gfield_date_month ginput_container ginput_container_date' id='{$field_id}_1_container'>\n <label for='{$field_id}_1' {$sub_label_class_attribute}>{$month_sub_label}</label>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_1' value='{$month_value}' {$tabindex} {$disabled_text} {$month_placeholder_attribute} {$month_html5_attributes}/>\n </div>" : "<div class='gfield_date_month ginput_container ginput_container_date' id='{$field_id}_1_container'>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_1' value='{$month_value}' {$tabindex} {$disabled_text} {$month_placeholder_attribute} {$month_html5_attributes}/>\n <label for='{$field_id}_1' {$sub_label_class_attribute}>{$month_sub_label}</label>\n </div>"; $tabindex = $this->get_tabindex(); $field_str .= $is_sub_label_above ? "<div class='gfield_date_day ginput_container ginput_container_date' id='{$field_id}_2_container'>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$day_sub_label}</label>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_2' value='{$day_value}' {$tabindex} {$disabled_text} {$day_placeholder_attribute} {$day_html5_attributes}/>\n </div>\n </div>" : "<div class='gfield_date_day ginput_container ginput_container_date' id='{$field_id}_2_container'>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_2' value='{$day_value}' {$tabindex} {$disabled_text} {$day_placeholder_attribute} {$day_html5_attributes}/>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$day_sub_label}</label>\n </div>\n </div>"; } break; default: $tabindex = $this->get_tabindex(); if ($date_type == 'datedropdown') { $field_str = "<div class='clear-multi'><div class='gfield_date_dropdown_month ginput_container ginput_container_date' id='{$field_id}_1_container'>" . $this->get_month_dropdown("input_{$id}[]", "{$field_id}_1", rgar($date_info, 'month'), $tabindex, $disabled_text, $month_placeholder_value) . '</div>'; $tabindex = $this->get_tabindex(); $field_str .= "<div class='gfield_date_dropdown_day ginput_container ginput_container_date' id='{$field_id}_2_container'>" . $this->get_day_dropdown("input_{$id}[]", "{$field_id}_2", rgar($date_info, 'day'), $tabindex, $disabled_text, $day_placeholder_value) . '</div>'; $tabindex = $this->get_tabindex(); $field_str .= "<div class='gfield_date_dropdown_year ginput_container ginput_container_date' id='{$field_id}_3_container'>" . $this->get_year_dropdown("input_{$id}[]", "{$field_id}_3", rgar($date_info, 'year'), $tabindex, $disabled_text, $year_placeholder_value, $form) . '</div></div>'; } else { $field_str = $is_sub_label_above ? "<div class='clear-multi'><div class='gfield_date_month ginput_container ginput_container_date' id='{$field_id}_1_container'>\n <label for='{$field_id}_1' {$sub_label_class_attribute}>{$month_sub_label}</label>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_1' value='{$month_value}' {$tabindex} {$disabled_text} {$month_placeholder_attribute} {$month_html5_attributes}/>\n </div>" : "<div class='clear-multi'><div class='gfield_date_month ginput_container ginput_container_date' id='{$field_id}_1_container'>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_1' value='{$month_value}' {$tabindex} {$disabled_text} {$month_placeholder_attribute} {$month_html5_attributes}/>\n <label for='{$field_id}_1' {$sub_label_class_attribute}>{$month_sub_label}</label>\n </div>"; $tabindex = $this->get_tabindex(); $field_str .= $is_sub_label_above ? "<div class='gfield_date_day ginput_container ginput_container_date' id='{$field_id}_2_container'>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$day_sub_label}</label>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_2' value='{$day_value}' {$tabindex} {$disabled_text} {$day_placeholder_attribute} {$day_html5_attributes}/>\n </div>" : "<div class='gfield_date_day ginput_container ginput_container_date' id='{$field_id}_2_container'>\n <input type='{$date_input_type}' maxlength='2' name='input_{$id}[]' id='{$field_id}_2' value='{$day_value}' {$tabindex} {$disabled_text} {$day_placeholder_attribute} {$day_html5_attributes}/>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$day_sub_label}</label>\n </div>"; $tabindex = $this->get_tabindex(); $field_str .= $is_sub_label_above ? "<div class='gfield_date_year ginput_container ginput_container_date' id='{$field_id}_3_container'>\n <label for='{$field_id}_3' {$sub_label_class_attribute}>{$year_sub_label}</label>\n <input type='{$date_input_type}' maxlength='4' name='input_{$id}[]' id='{$field_id}_3' value='{$year_value}' {$tabindex} {$disabled_text} {$year_placeholder_attribute} {$year_min_attribute} {$year_max_attribute} {$year_step_attribute}/>\n </div>\n </div>" : "<div class='gfield_date_year ginput_container ginput_container_date' id='{$field_id}_3_container'>\n <input type='{$date_input_type}' maxlength='4' name='input_{$id}[]' id='{$field_id}_3' value='{$year_value}' {$tabindex} {$disabled_text} {$year_placeholder_attribute} {$year_min_attribute} {$year_max_attribute} {$year_step_attribute}/>\n <label for='{$field_id}_3' {$sub_label_class_attribute}>{$year_sub_label}</label>\n </div>\n </div>"; } break; } return "<div id='{$field_id}' class='ginput_container ginput_container_date'>{$field_str}</div>"; } else { $picker_value = esc_attr(GFCommon::date_display($picker_value, $format)); $icon_class = $this->calendarIconType == 'none' ? 'datepicker_no_icon' : 'datepicker_with_icon'; $icon_url = empty($this->calendarIconUrl) ? GFCommon::get_base_url() . '/images/calendar.png' : $this->calendarIconUrl; $icon_url = esc_url($icon_url); $tabindex = $this->get_tabindex(); $class = esc_attr($class); return "<div class='ginput_container ginput_container_date'>\n <input name='input_{$id}' id='{$field_id}' type='text' value='{$picker_value}' class='datepicker {$class} {$format} {$icon_class}' {$tabindex} {$disabled_text} {$date_picker_placeholder}/>\n </div>\n <input type='hidden' id='gforms_calendar_icon_{$field_id}' class='gform_hidden' value='{$icon_url}'/>"; } } }
public static function prepare_date($date_format, $value) { $format = empty($date_format) ? "mdy" : $date_format; $date_info = GFCommon::parse_date($value, $format); if (!empty($date_info) && !GFCommon::is_empty_array($date_info)) { $value = sprintf("%s-%02d-%02d", $date_info["year"], $date_info["month"], $date_info["day"]); } else { $value = ""; } return $value; }
public static function get_field_input($field, $value = "", $lead_id = 0, $form_id = 0) { $id = $field["id"]; $field_id = IS_ADMIN || $form_id == 0 ? "input_{$id}" : "input_" . $form_id . "_{$id}"; $form_id = IS_ADMIN && empty($form_id) ? $_GET["id"] : $form_id; $size = $field["size"]; $disabled_text = IS_ADMIN && RG_CURRENT_VIEW != "entry" ? "disabled='disabled'" : ""; $class_suffix = RG_CURRENT_VIEW == "entry" ? "_admin" : ""; $class = $size . $class_suffix; $currency = ""; if (RG_CURRENT_VIEW == "entry") { $lead = RGFormsModel::get_lead($lead_id); $post_id = $lead["post_id"]; $post_link = ""; if (is_numeric($post_id) && self::is_post_field($field)) { $post_link = "You can <a href='post.php?action=edit&post={$post_id}'>edit this post</a> from the post page."; } $currency = $lead["currency"]; } $field_input = apply_filters("gform_field_input", "", $field, $value, $lead_id, $form_id); if ($field_input) { return $field_input; } //product fields are not editable if (RG_CURRENT_VIEW == "entry" && self::is_product_field($field["type"])) { return "<div class='ginput_container'>" . _e("Product fields are not editable", "gravityforms") . "</div>"; } else { if (RG_CURRENT_VIEW == "entry" && $field["type"] == "donation") { return "<div class='ginput_container'>" . _e("Donations are not editable", "gravityforms") . "</div>"; } } $max_length = ""; $html5_attributes = ""; switch (RGFormsModel::get_input_type($field)) { case "total": if (RG_CURRENT_VIEW == "entry") { return "<div class='ginput_container'><input type='text' name='input_{$id}' value='{$value}' /></div>"; } else { return "<div class='ginput_container'><span class='ginput_total ginput_total_{$form_id}'>" . self::to_money("0") . "</span><input type='hidden' name='input_{$id}' id='{$field_id}' class='gform_hidden'/></div>"; } break; case "singleproduct": $product_name = !is_array($value) || empty($value[$field["id"] . ".1"]) ? esc_attr($field["label"]) : esc_attr($value[$field["id"] . ".1"]); $price = !is_array($value) || empty($value[$field["id"] . ".2"]) ? $field["basePrice"] : esc_attr($value[$field["id"] . ".2"]); $quantity = is_array($value) ? esc_attr($value[$field["id"] . ".3"]) : ""; if (empty($price)) { $price = 0; } $form = RGFormsModel::get_form_meta($form_id); $has_quantity = sizeof(GFCommon::get_product_fields_by_type($form, array("quantity"), $field["id"])) > 0; if ($has_quantity) { $field["disableQuantity"] = true; } $quantity_field = ""; if (IS_ADMIN) { $style = $field["disableQuantity"] ? "style='display:none;'" : ""; $quantity_field = " <span class='ginput_quantity_label' {$style}>" . __("Quantity:", "gravityformspaypal") . "</span> <input type='text' name='input_{$id}.3' value='{$quantity}' id='ginput_quantity_{$form_id}_{$field["id"]}' class='ginput_quantity' size='10' />"; } else { if (!$field["disableQuantity"]) { $tabindex = self::get_tabindex(); $quantity_field .= " <span class='ginput_quantity_label'>" . __("Quantity:", "gravityformspaypal") . "</span> <input type='text' name='input_{$id}.3' value='{$quantity}' id='ginput_quantity_{$form_id}_{$field["id"]}' class='ginput_quantity' size='10' {$tabindex}/>"; } else { if (!is_numeric($quantity)) { $quantity = 1; } if (!$has_quantity) { $quantity_field .= "<input type='hidden' name='input_{$id}.3' value='{$quantity}' class='ginput_quantity_{$form_id}_{$field["id"]} gform_hidden' />"; } } } return "<div class='ginput_container'><input type='hidden' name='input_{$id}.1' value='{$product_name}' class='gform_hidden' /><span class='ginput_product_price_label'>" . __("Price:", "gravityformspaypal") . "</span> <span class='ginput_product_price' id='{$field_id}'>" . GFCommon::to_money($price, $currency) . "</span><input type='hidden' name='input_{$id}.2' id='ginput_base_price_{$form_id}_{$field["id"]}' class='gform_hidden' value='{$price}'/>{$quantity_field}</div>"; break; case "singleshipping": $price = !empty($value) ? $value : $field["basePrice"]; if (empty($price)) { $price = 0; } return "<div class='ginput_container'><input type='hidden' name='input_{$id}' value='{$price}' class='gform_hidden'/><span class='ginput_shipping_price' id='{$field_id}'>" . GFCommon::to_money($price, $currency) . "</span></div>"; break; case "website": $is_html5 = RGFormsModel::is_html5_enabled(); $value = empty($value) && !$is_html5 ? "http://" : $value; $html_input_type = $is_html5 ? "url" : "text"; $html5_attributes = $is_html5 ? "placeholder='http://'" : ""; case "text": if (empty($html_input_type)) { $html_input_type = "text"; } if ($field["enablePasswordInput"] && RG_CURRENT_VIEW != "entry") { $html_input_type = "password"; } if (is_numeric($field["maxLength"])) { $max_length = "maxlength='{$field["maxLength"]}'"; } if (!empty($post_link)) { return $post_link; } $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='%s' value='%s' class='%s' {$max_length} {$tabindex} {$html5_attributes} %s/></div>", $id, $field_id, $html_input_type, esc_attr($value), esc_attr($class), $disabled_text); break; case "email": if (!empty($post_link)) { return $post_link; } $html_input_type = RGFormsModel::is_html5_enabled() ? "email" : "text"; if (IS_ADMIN && RG_CURRENT_VIEW != "entry") { $single_style = $field["emailConfirmEnabled"] ? "style='display:none;'" : ""; $confirm_style = $field["emailConfirmEnabled"] ? "" : "style='display:none;'"; return "<div class='ginput_container ginput_single_email' {$single_style}><input name='input_{$id}' type='{$html_input_type}' class='" . esc_attr($class) . "' disabled='disabled' /></div><div class='ginput_complex ginput_container ginput_confirm_email' {$confirm_style} id='{$field_id}_container'><span id='{$field_id}_1_container' class='ginput_left'><input type='text' name='input_{$id}' id='{$field_id}' disabled='disabled' /><label for='{$field_id}'>" . apply_filters("gform_email_{$form_id}", apply_filters("gform_email", __("Enter Email", "gravityforms"), $form_id), $form_id) . "</label></span><span id='{$field_id}_2_container' class='ginput_right'><input type='text' name='input_{$id}_2' id='{$field_id}_2' disabled='disabled' /><label for='{$field_id}_2'>" . apply_filters("gform_email_confirm_{$form_id}", apply_filters("gform_email_confirm", __("Confirm Email", "gravityforms"), $form_id), $form_id) . "</label></span></div>"; } else { if ($field["emailConfirmEnabled"] && RG_CURRENT_VIEW != "entry") { $first_tabindex = self::get_tabindex(); $last_tabindex = self::get_tabindex(); return "<div class='ginput_complex ginput_container' id='{$field_id}_container'><span id='{$field_id}_1_container' class='ginput_left'><input type='{$html_input_type}' name='input_{$id}' id='{$field_id}' value='" . esc_attr($value) . "' {$first_tabindex} {$disabled_text}/><label for='{$field_id}'>" . apply_filters("gform_email_{$form_id}", apply_filters("gform_email", __("Enter Email", "gravityforms"), $form_id), $form_id) . "</label></span><span id='{$field_id}_2_container' class='ginput_right'><input type='{$html_input_type}' name='input_{$id}_2' id='{$field_id}_2' value='{$_POST["input_" . $id . "_2"]}' {$last_tabindex} {$disabled_text}/><label for='{$field_id}_2'>" . apply_filters("gform_email_confirm_{$form_id}", apply_filters("gform_email_confirm", __("Confirm Email", "gravityforms"), $form_id), $form_id) . "</label></span></div>"; } else { $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='%s' value='%s' class='%s' {$max_length} {$tabindex} {$html5_attributes} %s/></div>", $id, $field_id, $html_input_type, esc_attr($value), esc_attr($class), $disabled_text); } } break; case "honeypot": return "<div class='ginput_container'><input name='input_{$id}' id='{$field_id}' type='text' value=''/></div>"; break; case "hidden": if (!empty($post_link)) { return $post_link; } $field_type = IS_ADMIN ? "text" : "hidden"; $class_attribute = IS_ADMIN ? "" : "class='gform_hidden'"; return sprintf("<input name='input_%d' id='%s' type='{$field_type}' {$class_attribute} value='%s' %s/>", $id, $field_id, esc_attr($value), $disabled_text); break; case "html": $content = IS_ADMIN ? "<img class='gfield_html_block' src='" . self::get_base_url() . "/images/gf_html_admin_placeholder.jpg' alt='HTML Block'/>" : $field["content"]; return do_shortcode($content); break; case "adminonly_hidden": if (!is_array($field["inputs"])) { return sprintf("<input name='input_%d' id='%s' class='gform_hidden' type='hidden' value='%s'/>", $id, $field_id, esc_attr($value)); } $fields = ""; foreach ($field["inputs"] as $input) { $fields .= sprintf("<input name='input_%s' class='gform_hidden' type='hidden' value='%s'/>", $input["id"], esc_attr($value[$input["id"]])); } return $fields; break; case "number": if (!empty($post_link)) { return $post_link; } $instruction = ""; if (!IS_ADMIN) { $min = $field["rangeMin"]; $max = $field["rangeMax"]; $validation_class = $field["failed_validation"] ? "validation_message" : ""; $message = self::get_range_message($field); if (!$field["failed_validation"] && !empty($message) && empty($field["errorMessage"])) { $instruction = "<div class='instruction {$validation_class}'>" . $message . "</div>"; } } $html_input_type = RGFormsModel::is_html5_enabled() ? "number" : "text"; $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='{$html_input_type}' value='%s' class='%s' {$tabindex} %s/>%s</div>", $id, $field_id, esc_attr($value), esc_attr($class), $disabled_text, $instruction); case "donation": $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='%s' {$tabindex} %s/></div>", $id, $field_id, esc_attr($value), esc_attr($class), $disabled_text); case "price": $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='%s ginput_amount' {$tabindex} %s/></div>", $id, $field_id, esc_attr($value), esc_attr($class), $disabled_text); case "phone": if (!empty($post_link)) { return $post_link; } $instruction = $field["phoneFormat"] == "standard" ? __("Phone format:", "gravityforms") . " (###)###-####" : ""; $instruction_div = $field["failed_validation"] ? "<div class='instruction validation_message'>{$instruction}</div>" : ""; $html_input_type = RGFormsModel::is_html5_enabled() ? "tel" : "text"; $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='{$html_input_type}' value='%s' class='%s' {$tabindex} %s/>{$instruction_div}</div>", $id, $field_id, esc_attr($value), esc_attr($class), $disabled_text); case "textarea": if (!IS_ADMIN && !empty($field["maxLength"]) && is_numeric($field["maxLength"])) { $max_chars = self::get_counter_script($form_id, $field_id, $field["maxLength"]); } $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><textarea name='input_%d' id='%s' class='textarea %s' {$tabindex} %s rows='10' cols='50'>%s</textarea></div>{$max_chars}", $id, $field_id, esc_attr($class), $disabled_text, esc_html($value)); case "post_title": case "post_tags": case "post_custom_field": $tabindex = self::get_tabindex(); return !empty($post_link) ? $post_link : sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='%s' {$tabindex} %s/></div>", $id, $field_id, esc_attr($value), esc_attr($class), $disabled_text); break; case "post_content": case "post_excerpt": if (!IS_ADMIN && !empty($field["maxLength"]) && is_numeric($field["maxLength"])) { $max_chars = self::get_counter_script($form_id, $field_id, $field["maxLength"]); } $tabindex = self::get_tabindex(); return !empty($post_link) ? $post_link : sprintf("<div class='ginput_container'><textarea name='input_%d' id='%s' class='textarea %s' {$tabindex} %s rows='10' cols='50'>%s</textarea></div>{$max_chars}", $id, $field_id, esc_attr($class), $disabled_text, esc_html($value)); break; case "post_category": if (!empty($post_link)) { return $post_link; } if ($field["displayAllCategories"] && !IS_ADMIN) { $default_category = $field["categoryInitialItemEnabled"] ? "-1" : get_option('default_category'); $selected = empty($value) ? $default_category : $value; $args = array('echo' => 0, 'selected' => $selected, "class" => esc_attr($class) . " gfield_select", 'hide_empty' => 0, 'name' => "input_{$id}", 'orderby' => 'name', 'hierarchical' => true); if (self::$tab_index > 0) { $args["tab_index"] = self::$tab_index++; } if ($field["categoryInitialItemEnabled"]) { $args["show_option_none"] = empty($field["categoryInitialItem"]) ? " " : $field["categoryInitialItem"]; } return "<div class='ginput_container'>" . wp_dropdown_categories($args) . "</div>"; } else { $tabindex = self::get_tabindex(); $choices = self::get_select_choices($field, $value); //Adding first option if ($field["categoryInitialItemEnabled"]) { $selected = empty($value) ? "selected='selected'" : ""; $choices = "<option value='-1' {$selected}>{$field["categoryInitialItem"]}</option>" . $choices; } return sprintf("<div class='ginput_container'><select name='input_%d' id='%s' class='%s gfield_select' {$tabindex} %s>%s</select></div>", $id, $field_id, esc_attr($class), $disabled_text, $choices); } break; case "post_image": if (!empty($post_link)) { return $post_link; } $title = esc_attr($value[$field["id"] . ".1"]); $caption = esc_attr($value[$field["id"] . ".4"]); $description = esc_attr($value[$field["id"] . ".7"]); //hidding meta fields for admin $hidden_style = "style='display:none;'"; $title_style = !$field["displayTitle"] && IS_ADMIN ? $hidden_style : ""; $caption_style = !$field["displayCaption"] && IS_ADMIN ? $hidden_style : ""; $description_style = !$field["displayDescription"] && IS_ADMIN ? $hidden_style : ""; $file_label_style = IS_ADMIN && !($field["displayTitle"] || $field["displayCaption"] || $field["displayDescription"]) ? $hidden_style : ""; $hidden_class = ""; $file_info = RGFormsModel::get_temp_filename($form_id, "input_{$id}"); if ($file_info) { $hidden_class = " gform_hidden"; $file_label_style = $hidden_style; $preview = "<span class='ginput_preview'><strong>{$file_info["uploaded_filename"]}</strong> | <a href='javascript:;' onclick='gformDeleteUploadedFile({$form_id}, {$id});'>" . __("delete", "gravityforms") . "</a></span>"; } //in admin, render all meta fields to allow for immediate feedback, but hide the ones not selected $file_label = IS_ADMIN || $field["displayTitle"] || $field["displayCaption"] || $field["displayDescription"] ? "<label for='{$field_id}' class='ginput_post_image_file' {$file_label_style}>" . apply_filters("gform_postimage_file_{$form_id}", apply_filters("gform_postimage_file", __("File", "gravityforms"), $form_id), $form_id) . "</label>" : ""; $tabindex = self::get_tabindex(); $upload = sprintf("<span class='ginput_full{$class_suffix}'>{$preview}<input name='input_%d' id='%s' type='file' value='%s' class='%s' {$tabindex} %s/>{$file_label}</span>", $id, $field_id, esc_attr($value), esc_attr($class . $hidden_class), $disabled_text); $tabindex = self::get_tabindex(); $title_field = $field["displayTitle"] || IS_ADMIN ? sprintf("<span class='ginput_full{$class_suffix} ginput_post_image_title' {$title_style}><input type='text' name='input_%d.1' id='%s.1' value='%s' {$tabindex} %s/><label for='%s.1'>" . apply_filters("gform_postimage_title_{$form_id}", apply_filters("gform_postimage_title", __("Title", "gravityforms"), $form_id), $form_id) . "</label></span>", $id, $field_id, $title, $disabled_text, $field_id) : ""; $tabindex = self::get_tabindex(); $caption_field = $field["displayCaption"] || IS_ADMIN ? sprintf("<span class='ginput_full{$class_suffix} ginput_post_image_caption' {$caption_style}><input type='text' name='input_%d.4' id='%s.4' value='%s' {$tabindex} %s/><label for='%s.4'>" . apply_filters("gform_postimage_caption_{$form_id}", apply_filters("gform_postimage_caption", __("Caption", "gravityforms"), $form_id), $form_id) . "</label></span>", $id, $field_id, $caption, $disabled_text, $field_id) : ""; $tabindex = self::get_tabindex(); $description_field = $field["displayDescription"] || IS_ADMIN ? sprintf("<span class='ginput_full{$class_suffix} ginput_post_image_description' {$description_style}><input type='text' name='input_%d.7' id='%s.7' value='%s' {$tabindex} %s/><label for='%s.7'>" . apply_filters("gform_postimage_description_{$form_id}", apply_filters("gform_postimage_description", __("Description", "gravityforms"), $form_id), $form_id) . "</label></span>", $id, $field_id, $description, $disabled_text, $field_id) : ""; return "<div class='ginput_complex{$class_suffix} ginput_container'>" . $upload . $title_field . $caption_field . $description_field . "</div>"; break; case "select": if (!empty($post_link)) { return $post_link; } $logic_event = empty($field["conditionalLogicFields"]) || IS_ADMIN ? "" : "onchange='gf_apply_rules(" . $field["formId"] . "," . GFCommon::json_encode($field["conditionalLogicFields"]) . ");'"; $css_class = trim(esc_attr($class) . " gfield_select"); $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><select name='input_%d' id='%s' {$logic_event} class='%s' {$tabindex} %s>%s</select></div>", $id, $field_id, $css_class, $disabled_text, self::get_select_choices($field, $value)); case "checkbox": return sprintf("<div class='ginput_container'><ul class='gfield_checkbox' id='%s'>%s</ul></div>", $field_id, self::get_checkbox_choices($field, $value, $disabled_text)); case "radio": if (!empty($post_link)) { return $post_link; } return sprintf("<div class='ginput_container'><ul class='gfield_radio' id='%s'>%s</ul></div>", $field_id, self::get_radio_choices($field, $value, $disabled_text)); case "password": $first_tabindex = self::get_tabindex(); $last_tabindex = self::get_tabindex(); $strength_style = !$field["passwordStrengthEnabled"] ? "style='display:none;'" : ""; $strength = $field["passwordStrengthEnabled"] || IS_ADMIN ? "<div id='{$field_id}_strength_indicator' class='gfield_password_strength' {$strength_style}>" . __("Strength indicator", "gravityforms") . "</div><input type='hidden' class='gform_hidden' id='{$field_id}_strength' name='input_{$id}_strength' />" : ""; $action = "gformShowPasswordStrength(\"{$field_id}\");"; $onchange = $field["passwordStrengthEnabled"] ? "onchange='{$action}'" : ""; $onkeyup = $field["passwordStrengthEnabled"] ? "onkeyup='{$action}'" : ""; $script = $field["passwordStrengthEnabled"] && !IS_ADMIN ? "<script type=\"text/javascript\">if(window[\"gformShowPasswordStrength\"]) jQuery(document).ready(function(){{$action}});</script>" : ""; $pass = RGForms::post("input_" . $id . "_2"); return sprintf("<div class='ginput_complex{$class_suffix} ginput_container' id='{$field_id}_container'><span id='" . $field_id . "_1_container' class='ginput_left'><input type='password' name='input_%d' id='%s' {$onkeyup} {$onchange} value='%s' {$first_tabindex} %s/><label for='%s'>" . apply_filters("gform_password_{$form_id}", apply_filters("gform_password", __("Enter Password", "gravityforms"), $form_id), $form_id) . "</label></span><span id='" . $field_id . "_2_container' class='ginput_right'><input type='password' name='input_%d_2' id='%s_2' {$onkeyup} {$onchange} value='%s' {$last_tabindex} %s/><label for='%s_2'>" . apply_filters("gform_password_confirm_{$form_id}", apply_filters("gform_password_confirm", __("Confirm Password", "gravityforms"), $form_id), $form_id) . "</label></span>{$script}</div>{$strength}", $id, $field_id, $value, $disabled_text, $field_id, $id, $field_id, $pass, $disabled_text, $field_id); case "name": $prefix = ""; $first = ""; $last = ""; $suffix = ""; if (is_array($value)) { $prefix = esc_attr(RGForms::get($field["id"] . ".2", $value)); $first = esc_attr(RGForms::get($field["id"] . ".3", $value)); $last = esc_attr(RGForms::get($field["id"] . ".6", $value)); $suffix = esc_attr(RGForms::get($field["id"] . ".8", $value)); } switch ($field["nameFormat"]) { case "extended": $prefix_tabindex = self::get_tabindex(); $first_tabindex = self::get_tabindex(); $last_tabindex = self::get_tabindex(); $suffix_tabindex = self::get_tabindex(); return sprintf("<div class='ginput_complex{$class_suffix} ginput_container' id='{$field_id}'><span id='" . $field_id . "_2_container' class='name_prefix'><input type='text' name='input_%d.2' id='%s.2' value='%s' {$prefix_tabindex} %s/><label for='%s.2'>" . apply_filters("gform_name_prefix_{$form_id}", apply_filters("gform_name_prefix", __("Prefix", "gravityforms"), $form_id), $form_id) . "</label></span><span id='" . $field_id . "_3_container' class='name_first'><input type='text' name='input_%d.3' id='%s.3' value='%s' {$first_tabindex} %s/><label for='%s.3'>" . apply_filters("gform_name_first_{$form_id}", apply_filters("gform_name_first", __("First", "gravityforms"), $form_id), $form_id) . "</label></span><span id='" . $field_id . "_6_container' class='name_last'><input type='text' name='input_%d.6' id='%s.6' value='%s' {$last_tabindex} %s/><label for='%s.6'>" . apply_filters("gform_name_last_{$form_id}", apply_filters("gform_name_last", __("Last", "gravityforms"), $form_id), $form_id) . "</label></span><span id='" . $field_id . "_8_container' class='name_suffix'><input type='text' name='input_%d.8' id='%s.8' value='%s' {$suffix_tabindex} %s/><label for='%s.8'>" . apply_filters("gform_name_suffix_{$form_id}", apply_filters("gform_name_suffix", __("Suffix", "gravityforms"), $form_id), $form_id) . "</label></span></div>", $id, $field_id, $prefix, $disabled_text, $field_id, $id, $field_id, $first, $disabled_text, $field_id, $id, $field_id, $last, $disabled_text, $field_id, $id, $field_id, $suffix, $disabled_text, $field_id); case "simple": $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='%s' {$tabindex} %s/></div>", $id, $field_id, esc_attr($value), esc_attr($class), $disabled_text); default: $first_tabindex = self::get_tabindex(); $last_tabindex = self::get_tabindex(); return sprintf("<div class='ginput_complex{$class_suffix} ginput_container' id='{$field_id}'><span id='" . $field_id . "_3_container' class='ginput_left'><input type='text' name='input_%d.3' id='%s.3' value='%s' {$first_tabindex} %s/><label for='%s.3'>" . apply_filters("gform_name_first_{$form_id}", apply_filters("gform_name_first", __("First", "gravityforms"), $form_id), $form_id) . "</label></span><span id='" . $field_id . "_6_container' class='ginput_right'><input type='text' name='input_%d.6' id='%s.6' value='%s' {$last_tabindex} %s/><label for='%s.6'>" . apply_filters("gform_name_last_{$form_id}", apply_filters("gform_name_last", __("Last", "gravityforms"), $form_id), $form_id) . "</label></span></div>", $id, $field_id, $first, $disabled_text, $field_id, $id, $field_id, $last, $disabled_text, $field_id); } case "address": $street_value = ""; $street2_value = ""; $city_value = ""; $state_value = ""; $zip_value = ""; $country_value = ""; if (is_array($value)) { $street_value = esc_attr($value[$field["id"] . ".1"]); $street2_value = esc_attr($value[$field["id"] . ".2"]); $city_value = esc_attr($value[$field["id"] . ".3"]); $state_value = esc_attr($value[$field["id"] . ".4"]); $zip_value = esc_attr($value[$field["id"] . ".5"]); $country_value = esc_attr($value[$field["id"] . ".6"]); } $address_types = self::get_address_types($form_id); $addr_type = empty($field["addressType"]) ? "international" : $field["addressType"]; $address_type = $address_types[$addr_type]; $state_label = empty($address_type["state_label"]) ? __("State", "gravityforms") : $address_type["state_label"]; $zip_label = empty($address_type["zip_label"]) ? __("Zip Code", "gravityforms") : $address_type["zip_label"]; $hide_country = !empty($address_type["country"]) || $field["hideCountry"]; if (empty($country_value)) { $country_value = $field["defaultCountry"]; } if (empty($state_value)) { $state_value = $field["defaultState"]; } $country_list = self::get_country_dropdown($country_value); //address field $tabindex = self::get_tabindex(); $street_address = sprintf("<span class='ginput_full{$class_suffix}' id='" . $field_id . "_1_container'><input type='text' name='input_%d.1' id='%s_1' value='%s' {$tabindex} %s/><label for='%s_1' id='" . $field_id . "_1_label'>" . apply_filters("gform_address_street_{$form_id}", apply_filters("gform_address_street", __("Street Address", "gravityforms"), $form_id), $form_id) . "</label></span>", $id, $field_id, $street_value, $disabled_text, $field_id); //address line 2 field $style = IS_ADMIN && $field["hideAddress2"] ? "style='display:none;'" : ""; if (IS_ADMIN || !$field["hideAddress2"]) { $tabindex = self::get_tabindex(); $street_address2 = sprintf("<span class='ginput_full{$class_suffix}' id='" . $field_id . "_2_container' {$style}><input type='text' name='input_%d.2' id='%s_2' value='%s' {$tabindex} %s/><label for='%s_2' id='" . $field_id . "_2_label'>" . apply_filters("gform_address_street2_{$form_id}", apply_filters("gform_address_street2", __("Address Line 2", "gravityforms"), $form_id), $form_id) . "</label></span>", $id, $field_id, $street2_value, $disabled_text, $field_id); } //city field $tabindex = self::get_tabindex(); $city = sprintf("<span class='ginput_left{$class_suffix}' id='" . $field_id . "_3_container'><input type='text' name='input_%d.3' id='%s_3' value='%s' {$tabindex} %s/><label for='%s_3' id='{$field_id}.3_label'>" . apply_filters("gform_address_city_{$form_id}", apply_filters("gform_address_city", __("City", "gravityforms"), $form_id), $form_id) . "</label></span>", $id, $field_id, $city_value, $disabled_text, $field_id); //state field $style = IS_ADMIN && $field["hideState"] ? "style='display:none;'" : ""; if (IS_ADMIN || !$field["hideState"]) { $state_field = self::get_state_field($field, $id, $field_id, $state_value, $disabled_text, $form_id); $state = sprintf("<span class='ginput_right{$class_suffix}' id='" . $field_id . "_4_container' {$style}>{$state_field}<label for='%s.4' id='" . $field_id . "_4_label'>" . apply_filters("gform_address_state_{$form_id}", apply_filters("gform_address_state", $state_label, $form_id), $form_id) . "</label></span>", $field_id); } else { $state = sprintf("<input type='hidden' class='gform_hidden' name='input_%d.4' id='%s_4' value='%s'/>", $id, $field_id, $state_value); } //zip field $tabindex = self::get_tabindex(); $zip = sprintf("<span class='ginput_left{$class_suffix}' id='" . $field_id . "_5_container'><input type='text' name='input_%d.5' id='%s_5' value='%s' {$tabindex} %s/><label for='%s_5' id='" . $field_id . "_5_label'>" . apply_filters("gform_address_zip_{$form_id}", apply_filters("gform_address_zip", $zip_label, $form_id), $form_id) . "</label></span>", $id, $field_id, $zip_value, $disabled_text, $field_id); if (IS_ADMIN || !$hide_country) { $style = $hide_country ? "style='display:none;'" : ""; $tabindex = self::get_tabindex(); $country = sprintf("<span class='ginput_right{$class_suffix}' id='" . $field_id . "_6_container' {$style}><select name='input_%d.6' id='%s_6' {$tabindex} %s>%s</select><label for='%s_6' id='" . $field_id . "_6_label'>" . apply_filters("gform_address_country_{$form_id}", apply_filters("gform_address_country", __("Country", "gravityforms"), $form_id), $form_id) . "</label></span>", $id, $field_id, $disabled_text, $country_list, $field_id); } else { $country = sprintf("<input type='hidden' class='gform_hidden' name='input_%d.6' id='%s_6' value='%s'/>", $id, $field_id, $country_value); } return "<div class='ginput_complex{$class_suffix} ginput_container' id='{$field_id}'>" . $street_address . $street_address2 . $city . $state . $zip . $country . "</div>"; case "date": if (!empty($post_link)) { return $post_link; } $format = empty($field["dateFormat"]) ? "mdy" : esc_attr($field["dateFormat"]); if (IS_ADMIN && RG_CURRENT_VIEW != "entry") { $datepicker_display = $field["dateType"] == "datefield" ? "none" : "inline"; $dropdown_display = $field["dateType"] == "datefield" ? "inline" : "none"; $icon_display = $field["calendarIconType"] == "calendar" ? "inline" : "none"; $month_field = "<div class='gfield_date_month ginput_date' id='gfield_input_date_month' style='display:{$dropdown_display}'><input name='ginput_month' type='text' disabled='disabled'/><label>" . __("MM", "gravityforms") . "</label></div>"; $day_field = "<div class='gfield_date_day ginput_date' id='gfield_input_date_day' style='display:{$dropdown_display}'><input name='ginput_day' type='text' disabled='disabled'/><label>" . __("DD", "gravityforms") . "</label></div>"; $year_field = "<div class='gfield_date_year ginput_date' id='gfield_input_date_year' style='display:{$dropdown_display}'><input type='text' name='ginput_year' disabled='disabled'/><label>" . __("YYYY", "gravityforms") . "</label></div>"; $field_string = "<div class='ginput_container' id='gfield_input_datepicker' style='display:{$datepicker_display}'><input name='ginput_datepicker' type='text' /><img src='" . GFCommon::get_base_url() . "/images/calendar.png' id='gfield_input_datepicker_icon' style='display:{$icon_display}'/></div>"; $field_string .= $field["dateFormat"] == "dmy" ? $day_field . $month_field . $year_field : $month_field . $day_field . $year_field; return $field_string; } else { $date_info = GFCommon::parse_date($value, $format); if ($field["dateType"] == "datefield") { if ($format == "mdy") { $tabindex = self::get_tabindex(); $field_str = sprintf("<div class='clear-multi'><div class='gfield_date_month ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.1' value='%s' {$tabindex} %s/><label for='%s.1'>" . __("MM", "gravityforms") . "</label></div>", $field_id, $id, $field_id, $date_info["month"], $disabled_text, $field_id); $tabindex = self::get_tabindex(); $field_str .= sprintf("<div class='gfield_date_day ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.2' value='%s' {$tabindex} %s/><label for='%s.2'>" . __("DD", "gravityforms") . "</label></div>", $field_id, $id, $field_id, $date_info["day"], $disabled_text, $field_id); } else { $tabindex = self::get_tabindex(); $field_str = sprintf("<div class='clear-multi'><div class='gfield_date_day ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.2' value='%s' {$tabindex} %s/><label for='%s.2'>" . __("DD", "gravityforms") . "</label></div>", $field_id, $id, $field_id, $date_info["day"], $disabled_text, $field_id); $tabindex = self::get_tabindex(); $field_str .= sprintf("<div class='gfield_date_month ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.1' value='%s' {$tabindex} %s/><label for='%s.1'>" . __("MM", "gravityforms") . "</label></div>", $field_id, $id, $field_id, $date_info["month"], $disabled_text, $field_id); } $tabindex = self::get_tabindex(); $field_str .= sprintf("<div class='gfield_date_year ginput_container' id='%s'><input type='text' maxlength='4' name='input_%d[]' id='%s.3' value='%s' {$tabindex} %s/><label for='%s.3'>" . __("YYYY", "gravityforms") . "</label></div></div>", $field_id, $id, $field_id, $date_info["year"], $disabled_text, $field_id); return $field_str; } else { $value = GFCommon::date_display($value, $format); $icon_class = $field["calendarIconType"] == "none" ? "datepicker_no_icon" : "datepicker_with_icon"; $icon_url = empty($field["calendarIconUrl"]) ? GFCommon::get_base_url() . "/images/calendar.png" : $field["calendarIconUrl"]; $tabindex = self::get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='datepicker %s %s %s' {$tabindex} %s/> </div><input type='hidden' id='gforms_calendar_icon_{$field_id}' class='gform_hidden' value='{$icon_url}'/>", $id, $field_id, esc_attr($value), esc_attr($class), $format, $icon_class, $disabled_text); } } case "time": if (!empty($post_link)) { return $post_link; } if (!is_array($value) && !empty($value)) { preg_match('/^(\\d*):(\\d*) (.*)$/', $value, $matches); $hour = esc_attr($matches[1]); $minute = esc_attr($matches[2]); $am_selected = $matches[3] == "am" ? "selected='selected'" : ""; $pm_selected = $matches[3] == "pm" ? "selected='selected'" : ""; } else { $hour = esc_attr($value[0]); $minute = esc_attr($value[1]); $am_selected = $value[2] == "am" ? "selected='selected'" : ""; $pm_selected = $value[2] == "pm" ? "selected='selected'" : ""; } $hour_tabindex = self::get_tabindex(); $minute_tabindex = self::get_tabindex(); $ampm_tabindex = self::get_tabindex(); return sprintf("<div class='clear-multi'><div class='gfield_time_hour ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.1' value='%s' {$hour_tabindex} %s/> : <label for='%s.1'>" . __("HH", "gravityforms") . "</label></div><div class='gfield_time_minute ginput_container'><input type='text' maxlength='2' name='input_%d[]' id='%s.2' value='%s' {$minute_tabindex} %s/><label for='%s.2'>" . __("MM", "gravityforms") . "</label></div><div class='gfield_time_ampm ginput_container'><select name='input_%d[]' id='%s.3' {$ampm_tabindex} %s><option value='am' %s>" . __("AM", "gravityforms") . "</option><option value='pm' %s>" . __("PM", "gravityforms") . "</option></select></div></div>", $field_id, $id, $field_id, $hour, $disabled_text, $field_id, $id, $field_id, $minute, $disabled_text, $field_id, $id, $field_id, $disabled_text, $am_selected, $pm_selected); case "fileupload": $tabindex = self::get_tabindex(); $upload = sprintf("<input name='input_%d' id='%s' type='file' value='%s' size='20' class='%s' {$tabindex} %s/>", $id, $field_id, esc_attr($value), esc_attr($class), $disabled_text); if (IS_ADMIN && !empty($value)) { $value = esc_attr($value); $preview = sprintf("<div id='preview_%d'><a href='%s' target='_blank' alt='%s' title='%s'>%s</a><a href='%s' target='_blank' alt='" . __("Download file", "gravityforms") . "' title='" . __("Download file", "gravityforms") . "'><img src='%s' style='margin-left:10px;'/></a><a href='javascript:void(0);' alt='" . __("Delete file", "gravityforms") . "' title='" . __("Delete file", "gravityforms") . "' onclick='DeleteFile(%d,%d);' ><img src='%s' style='margin-left:10px;'/></a></div>", $id, $value, $value, $value, GFCommon::truncate_url($value), $value, GFCommon::get_base_url() . "/images/download.png", $lead_id, $id, GFCommon::get_base_url() . "/images/delete.png"); return $preview . "<div id='upload_{$id}' style='display:none;'>{$upload}</div>"; } else { $file_info = RGFormsModel::get_temp_filename($form_id, "input_{$id}"); if ($file_info && !$field["failed_validation"]) { $preview = "<span class='ginput_preview'><strong>{$file_info["uploaded_filename"]}</strong> | <a href='javascript:;' onclick='gformDeleteUploadedFile({$form_id}, {$id});'>" . __("delete", "gravityforms") . "</a></span>"; return "<div class='ginput_container'>" . str_replace(" class='", " class='gform_hidden ", $upload) . " {$preview}</div>"; } else { return "<div class='ginput_container'>{$upload}</div>"; } } case "captcha": switch ($field["captchaType"]) { case "simple_captcha": $size = empty($field["simpleCaptchaSize"]) ? "medium" : $field["simpleCaptchaSize"]; $captcha = self::get_captcha($field); $tagindex = self::get_tabindex(); $dimensions = IS_ADMIN ? "" : "width='{$captcha["width"]}' height='{$captcha["height"]}'"; return "<div class='gfield_captcha_container'><img class='gfield_captcha' src='{$captcha["url"]}' alt='' {$dimensions} /><div class='gfield_captcha_input_container simple_captcha_{$size}'><input type='text' name='input_{$id}' id='input_{$field_id}' /><input type='hidden' name='input_captcha_prefix_{$id}' value='{$captcha["prefix"]}' /></div></div>"; break; case "math": $size = empty($field["simpleCaptchaSize"]) ? "medium" : $field["simpleCaptchaSize"]; $captcha_1 = self::get_math_captcha($field, 1); $captcha_2 = self::get_math_captcha($field, 2); $captcha_3 = self::get_math_captcha($field, 3); $tagindex = self::get_tabindex(); $dimensions = IS_ADMIN ? "" : "width='{$captcha_1["width"]}' height='{$captcha_1["height"]}'"; return "<div class='gfield_captcha_container'><img class='gfield_captcha' src='{$captcha_1["url"]}' alt='' {$dimensions} /><img class='gfield_captcha' src='{$captcha_2["url"]}' alt='' {$dimensions} /><img class='gfield_captcha' src='{$captcha_3["url"]}' alt='' {$dimensions} /><div class='gfield_captcha_input_container math_{$size}'><input type='text' name='input_{$id}' id='input_{$field_id}' /><input type='hidden' name='input_captcha_prefix_{$id}' value='{$captcha_1["prefix"]},{$captcha_2["prefix"]},{$captcha_3["prefix"]}' /></div></div>"; break; default: if (!function_exists("recaptcha_get_html")) { require_once GFCommon::get_base_path() . '/recaptchalib.php'; } $theme = empty($field["captchaTheme"]) ? "red" : esc_attr($field["captchaTheme"]); $publickey = get_option("rg_gforms_captcha_public_key"); $privatekey = get_option("rg_gforms_captcha_private_key"); if (IS_ADMIN) { if (empty($publickey) || empty($privatekey)) { return "<div class='captcha_message'>" . __("To use the reCaptcha field you must first do the following:", "gravityforms") . "</div><div class='captcha_message'>1 - <a href='https://admin.recaptcha.net/recaptcha/createsite/?app=php' target='_blank'>" . __(sprintf("Sign up%s for a free reCAPTCHA account", "</a>"), "gravityforms") . "</div><div class='captcha_message'>2 - " . __(sprintf("Enter your reCAPTCHA keys in the %ssettings page%s", "<a href='?page=gf_settings'>", "</a>"), "gravityforms") . "</div>"; } else { return "<div class='ginput_container'><img class='gfield_captcha' src='" . GFCommon::get_base_url() . "/images/captcha_{$theme}.jpg' alt='reCAPTCHA' title='reCAPTCHA'/></div>"; } } else { $language = empty($field["captchaLanguage"]) ? "en" : esc_attr($field["captchaLanguage"]); $options = "<script type='text/javascript'>var RecaptchaOptions = {theme : '{$theme}', lang : '{$language}'}; if(parseInt('" . self::$tab_index . "') > 0) {RecaptchaOptions.tabindex = " . self::$tab_index++ . ";}</script>"; $is_ssl = !empty($_SERVER['HTTPS']); return $options . "<div class='ginput_container' id='{$field_id}'>" . recaptcha_get_html($publickey, null, $is_ssl) . "</div>"; } } break; } }
static function parse_field_date($field) { $date_value = rgpost("input_{$field['id']}"); $date_format = empty($field['dateFormat']) ? 'mdy' : esc_attr($field['dateFormat']); $date_info = GFCommon::parse_date($date_value, $date_format); if (empty($date_info)) { return false; } return strtotime("{$date_info['year']}-{$date_info['month']}-{$date_info['day']}"); }
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; }
function pronamic_events_gform_parse_date($value, $format) { $date_info = GFCommon::parse_date($value, $format); return $date_info; }
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; }
private static function prepare_value($form_id, $field, $value, $input_name) { $input_type = self::get_input_type($field); switch ($input_type) { case "post_category": $cat = get_category($value); $value = $cat->name; break; case "phone": if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) { $value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]); } break; case "time": if (!is_array($value) && !empty($value)) { preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches); $value = array(); $value[0] = $matches[1]; $value[1] = $matches[2]; $value[2] = $matches[3]; } $hour = empty($value[0]) ? "0" : strip_tags($value[0]); $minute = empty($value[1]) ? "0" : strip_tags($value[1]); $ampm = strip_tags($value[2]); if (!(empty($hour) && empty($minute))) { $value = sprintf("%02d:%02d %s", $hour, $minute, $ampm); } else { $value = ""; } break; case "date": $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"]; $date_info = GFCommon::parse_date($value, $format); if (!empty($date_info)) { $value = sprintf("%d-%02d-%02d", $date_info["year"], $date_info["month"], $date_info["day"]); } else { $value = ""; } break; case "post_image": $url = self::get_fileupload_value($form_id, $input_name); $image_title = isset($_POST["{$input_name}_1"]) ? strip_tags($_POST["{$input_name}_1"]) : ""; $image_caption = isset($_POST["{$input_name}_4"]) ? strip_tags($_POST["{$input_name}_4"]) : ""; $image_description = isset($_POST["{$input_name}_7"]) ? strip_tags($_POST["{$input_name}_7"]) : ""; $value = !empty($url) ? $url . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : ""; break; case "fileupload": $value = self::get_fileupload_value($form_id, $input_name); break; case "number": $value = GFCommon::clean_number($value); break; default: $value = stripslashes($value); //allow HTML for certain field types if (!in_array($field["type"], array("post_custom_field", "post_title", "post_content", "post_excerpt", "post_tags")) && !in_array($input_type, array("checkbox", "radio"))) { $value = strip_tags($value); } //do not save price fields with blank price if ($field["enablePrice"]) { list($label, $price) = explode("|", $value); $is_empty = strlen(trim($price)) <= 0; if ($is_empty) { $value = ""; } } break; } return $value; }
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_field_input($field, $value = "", $lead_id = 0, $form_id = 0) { $id = $field["id"]; $field_id = IS_ADMIN || $form_id == 0 ? "input_{$id}" : "input_" . $form_id . "_{$id}"; $size = $field["size"]; $disabled_text = IS_ADMIN && RG_CURRENT_VIEW != "entry" ? "disabled='disabled'" : ""; $class_suffix = RG_CURRENT_VIEW == "entry" ? "_admin" : ""; $class = $size . $class_suffix; if (RG_CURRENT_VIEW == "entry") { $lead = RGFormsModel::get_lead($lead_id); $post_id = $lead["post_id"]; $post_link = ""; if (is_numeric($post_id) && self::is_post_field($field)) { $post_link = "You can <a href='post.php?action=edit&post={$post_id}'>edit this post</a> from the post page."; } } switch (RGFormsModel::get_input_type($field)) { case "website": $value = empty($value) ? "http://" : $value; case "text": case "email": if (!empty($post_link)) { return $post_link; } return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='%s' tabindex='%d' %s/></div>", $id, $field_id, esc_attr($value), esc_attr($class), self::$tab_index++, $disabled_text); break; case "hidden": if (!empty($post_link)) { return $post_link; } $field_type = IS_ADMIN ? "text" : "hidden"; $class_attribute = IS_ADMIN ? "" : "class='gform_hidden'"; return sprintf("<input name='input_%d' id='%s' type='{$field_type}' {$class_attribute} value='%s' %s/>", $id, $field_id, esc_attr($value), $disabled_text); break; case "adminonly_hidden": if (!is_array($field["inputs"])) { return sprintf("<input name='input_%d' id='%s' class='gform_hidden' type='hidden' value='%s'/>", $id, $field_id, esc_attr($value)); } $fields = ""; foreach ($field["inputs"] as $input) { $fields .= sprintf("<input name='input_%s' class='gform_hidden' type='hidden' value='%s'/>", $input["id"], esc_attr($value[$input["id"]])); } return $fields; break; case "number": if (!empty($post_link)) { return $post_link; } if (!IS_ADMIN) { $min = $field["rangeMin"]; $max = $field["rangeMax"]; $validation_class = $field["failed_validation"] ? "validation_message" : ""; $message = self::get_range_message($field); if (!$field["failed_validation"] && !empty($message) && empty($field["errorMessage"])) { $instruction = "<div class='instruction {$validation_class}'>" . $message . "</div>"; } } return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='%s' tabindex='%d' %s/>%s</div>", $id, $field_id, esc_attr($value), esc_attr($class), self::$tab_index++, $disabled_text, $instruction); case "phone": if (!empty($post_link)) { return $post_link; } $instruction = $field["phoneFormat"] == "standard" ? __("Phone format:", "gravityforms") . " (###)###-####" : ""; $instruction_div = $field["failed_validation"] ? "<div class='instruction validation_message'>{$instruction}</div>" : ""; return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='%s' tabindex='%d' %s/>{$instruction_div}</div>", $id, $field_id, esc_attr($value), esc_attr($class), self::$tab_index++, $disabled_text); case "textarea": return sprintf("<div class='ginput_container'><textarea name='input_%d' id='%s' class='textarea %s' tabindex='%d' %s rows='10' cols='50'>%s</textarea></div>", $id, $field_id, esc_attr($class), self::$tab_index++, $disabled_text, esc_html($value)); case "post_title": case "post_tags": case "post_custom_field": return !empty($post_link) ? $post_link : sprintf("<div><input name='input_%d' id='%s' type='text' value='%s' class='%s' tabindex='%d' %s/></div>", $id, $field_id, esc_attr($value), esc_attr($class), self::$tab_index++, $disabled_text); break; case "post_content": case "post_excerpt": return !empty($post_link) ? $post_link : sprintf("<div><textarea name='input_%d' id='%s' class='textarea %s' tabindex='%d' %s rows='10' cols='50'>%s</textarea></div>", $id, $field_id, esc_attr($class), self::$tab_index++, $disabled_text, esc_html($value)); break; case "post_category": if (!empty($post_link)) { return $post_link; } if ($field["displayAllCategories"] && !IS_ADMIN) { $selected = empty($value) ? get_option('default_category') : $value; return "<div class='ginput_container'>" . wp_dropdown_categories(array('echo' => 0, 'selected' => $selected, "class" => esc_attr($class) . " gfield_select", "tab_index" => self::$tab_index++, 'hide_empty' => 0, 'name' => "input_{$id}", 'orderby' => 'name', 'hierarchical' => true)) . "</div>"; } else { return sprintf("<div class='ginput_container'><select name='input_%d' id='%s' class='%s gfield_select' tabindex='%d' %s>%s</select></div>", $id, $field_id, esc_attr($class), self::$tab_index++, $disabled_text, self::get_select_choices($field, $value)); } break; case "post_image": if (!empty($post_link)) { return $post_link; } $title = esc_attr($value[$field["id"] . ".1"]); $caption = esc_attr($value[$field["id"] . ".4"]); $description = esc_attr($value[$field["id"] . ".7"]); //hidding meta fields for admin $hidden_style = "style='display:none;'"; $title_style = !$field["displayTitle"] && IS_ADMIN ? $hidden_style : ""; $caption_style = !$field["displayCaption"] && IS_ADMIN ? $hidden_style : ""; $description_style = !$field["displayDescription"] && IS_ADMIN ? $hidden_style : ""; $file_label_style = IS_ADMIN && !($field["displayTitle"] || $field["displayCaption"] || $field["displayDescription"]) ? $hidden_style : ""; //in admin, render all meta fields to allow for immediate feedback, but hide the ones not selected $file_label = IS_ADMIN || $field["displayTitle"] || $field["displayCaption"] || $field["displayDescription"] ? "<label for='{$field_id}' class='ginput_post_image_file' {$file_label_style}>" . apply_filters("gform_postimage_file", __("File", "gravityforms"), $form_id) . "</label>" : ""; $upload = sprintf("<span class='ginput_full{$class_suffix}'><input name='input_%d' id='%s' type='file' value='%s' class='%s' tabindex='%d' %s/>{$file_label}</span>", $id, $field_id, esc_attr($value), esc_attr($class), self::$tab_index++, $disabled_text); $title_field = $field["displayTitle"] || IS_ADMIN ? sprintf("<span class='ginput_full{$class_suffix} ginput_post_image_title' {$title_style}><input type='text' name='input_%d.1' id='%s.1' value='%s' tabindex='%d' %s/><label for='%s.1'>" . apply_filters("gform_postimage_title", __("Title", "gravityforms"), $form_id) . "</label></span>", $id, $field_id, $title, self::$tab_index++, $disabled_text, $field_id) : ""; $caption_field = $field["displayCaption"] || IS_ADMIN ? sprintf("<span class='ginput_full{$class_suffix} ginput_post_image_caption' {$caption_style}><input type='text' name='input_%d.4' id='%s.4' value='%s' tabindex='%d' %s/><label for='%s.4'>" . apply_filters("gform_postimage_title", __("Caption", "gravityforms"), $form_id) . "</label></span>", $id, $field_id, $caption, self::$tab_index++, $disabled_text, $field_id) : ""; $description_field = $field["displayDescription"] || IS_ADMIN ? sprintf("<span class='ginput_full{$class_suffix} ginput_post_image_description' {$description_style}><input type='text' name='input_%d.7' id='%s.7' value='%s' tabindex='%d' %s/><label for='%s.7'>" . apply_filters("gform_postimage_title", __("Description", "gravityforms"), $form_id) . "</label></span>", $id, $field_id, $description, self::$tab_index++, $disabled_text, $field_id) : ""; return "<div class='ginput_complex{$class_suffix} ginput_container'>" . $upload . $title_field . $caption_field . $description_field . "</div>"; break; case "select": if (!empty($post_link)) { return $post_link; } $logic_event = empty($field["conditionalLogicFields"]) || IS_ADMIN ? "" : "onchange='gf_apply_rules(" . $field["formId"] . "," . GFCommon::json_encode($field["conditionalLogicFields"]) . ");'"; $css_class = trim(esc_attr($class) . " gfield_select"); return sprintf("<div class='ginput_container'><select name='input_%d' id='%s' {$logic_event} class='%s' tabindex='%d' %s>%s</select></div>", $id, $field_id, $css_class, self::$tab_index++, $disabled_text, self::get_select_choices($field, $value)); case "checkbox": return sprintf("<div class='ginput_container'><ul class='gfield_checkbox' id='%s'>%s</ul></div>", $field_id, self::get_checkbox_choices($field, $value, $disabled_text)); case "radio": if (!empty($post_link)) { return $post_link; } return sprintf("<div class='ginput_container'><ul class='gfield_radio' id='%s'>%s</ul></div>", $field_id, self::get_radio_choices($field, $value, $disabled_text)); case "name": if (is_array($value)) { $prefix = esc_attr($value[$field["id"] . ".2"]); $first = esc_attr($value[$field["id"] . ".3"]); $last = esc_attr($value[$field["id"] . ".6"]); $suffix = esc_attr($value[$field["id"] . ".8"]); } switch ($field["nameFormat"]) { case "extended": return sprintf("<div class='ginput_complex{$class_suffix} ginput_container' id='{$field_id}'><span id='" . $field_id . "_2_container' class='name_prefix'><input type='text' name='input_%d.2' id='%s.2' value='%s' tabindex='%d' %s/><label for='%s.2'>" . apply_filters("gform_name_prefix", __("Prefix", "gravityforms"), $form_id) . "</label></span><span id='" . $field_id . "_3_container' class='name_first'><input type='text' name='input_%d.3' id='%s.3' value='%s' tabindex='%d' %s/><label for='%s.3'>" . apply_filters("gform_name_first", __("First", "gravityforms"), $form_id) . "</label></span><span id='" . $field_id . "_6_container' class='name_last'><input type='text' name='input_%d.6' id='%s.6' value='%s' tabindex='%d' %s/><label for='%s.6'>" . apply_filters("gform_name_last", __("Last", "gravityforms"), $form_id) . "</label></span><span id='" . $field_id . "_8_container' class='name_suffix'><input type='text' name='input_%d.8' id='%s.8' value='%s' tabindex='%d' %s/><label for='%s.8'>" . apply_filters("gform_name_suffix", __("Suffix", "gravityforms"), $form_id) . "</label></span></div>", $id, $field_id, $prefix, self::$tab_index++, $disabled_text, $field_id, $id, $field_id, $first, self::$tab_index++, $disabled_text, $field_id, $id, $field_id, $last, self::$tab_index++, $disabled_text, $field_id, $id, $field_id, $suffix, self::$tab_index++, $disabled_text, $field_id); case "simple": return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='%s' tabindex='%d' %s/></div>", $id, $field_id, esc_attr($value), esc_attr($class), self::$tab_index++, $disabled_text); default: return sprintf("<div class='ginput_complex{$class_suffix} ginput_container' id='{$field_id}'><span id='" . $field_id . "_3_container' class='ginput_left'><input type='text' name='input_%d.3' id='%s.3' value='%s' tabindex='%d' %s/><label for='%s.3'>" . apply_filters("gform_name_first", __("First", "gravityforms"), $form_id) . "</label></span><span id='" . $field_id . "_6_container' class='ginput_right'><input type='text' name='input_%d.6' id='%s.6' value='%s' tabindex='%d' %s/><label for='%s.6'>" . apply_filters("gform_name_last", __("Last", "gravityforms"), $form_id) . "</label></span></div>", $id, $field_id, $first, self::$tab_index++, $disabled_text, $field_id, $id, $field_id, $last, self::$tab_index++, $disabled_text, $field_id); } case "address": if (is_array($value)) { $street_value = esc_attr($value[$field["id"] . ".1"]); $street2_value = esc_attr($value[$field["id"] . ".2"]); $city_value = esc_attr($value[$field["id"] . ".3"]); $state_value = esc_attr($value[$field["id"] . ".4"]); $zip_value = esc_attr($value[$field["id"] . ".5"]); $country_value = esc_attr($value[$field["id"] . ".6"]); } switch ($field["addressType"]) { case "us": $state_label = __("State", "gravityforms"); $zip_label = __("Zip Code", "gravityforms"); $hide_country = true; break; case "canadian": $state_label = __("Province", "gravityforms"); $zip_label = __("Postal Code", "gravityforms"); $hide_country = true; break; default: $state_label = __("State / Province / Region", "gravityforms"); $zip_label = __("Zip / Postal Code", "gravityforms"); $hide_country = $field["hideCountry"]; } if (empty($country_value)) { $country_value = $field["defaultCountry"]; } $country_list = self::get_country_dropdown($country_value); //address field $street_address = sprintf("<span class='ginput_full{$class_suffix}' id='" . $field_id . "_1_container'><input type='text' name='input_%d.1' id='%s_1' value='%s' tabindex='%d' %s/><label for='%s_1' id='" . $field_id . "_1_label'>" . apply_filters("gform_address_street", __("Street Address", "gravityforms"), $form_id) . "</label></span>", $id, $field_id, $street_value, self::$tab_index++, $disabled_text, $field_id); //address line 2 field $style = IS_ADMIN && $field["hideAddress2"] ? "style='display:none;'" : ""; $street_address2 = IS_ADMIN || !$field["hideAddress2"] ? sprintf("<span class='ginput_full{$class_suffix}' id='" . $field_id . "_2_container' {$style}><input type='text' name='input_%d.2' id='%s_2' value='%s' tabindex='%d' %s/><label for='%s_2' id='" . $field_id . "_2_label'>" . apply_filters("gform_address_street2", __("Address Line 2", "gravityforms"), $form_id) . "</label></span>", $id, $field_id, $street2_value, self::$tab_index++, $disabled_text, $field_id) : ""; //city field $city = sprintf("<span class='ginput_left{$class_suffix}' id='" . $field_id . "_3_container'><input type='text' name='input_%d.3' id='%s_3' value='%s' tabindex='%d' %s/><label for='%s_3' id='{$field_id}.3_label'>" . apply_filters("gform_address_city", __("City", "gravityforms"), $form_id) . "</label></span>", $id, $field_id, $city_value, self::$tab_index++, $disabled_text, $field_id); //state field $state_field = self::get_state_field($field, $id, $field_id, $state_value, $disabled_text); $state = sprintf("<span class='ginput_right{$class_suffix}' id='" . $field_id . "_4_container'>{$state_field}<label for='%s.4' id='" . $field_id . "_4_label'>" . apply_filters("gform_address_state", $state_label, $form_id) . "</label></span>", $field_id); $zip = sprintf("<span class='ginput_left{$class_suffix}' id='" . $field_id . "_5_container'><input type='text' name='input_%d.5' id='%s_5' value='%s' tabindex='%d' %s/><label for='%s_5' id='" . $field_id . "_5_label'>" . apply_filters("gform_address_zip", $zip_label, $form_id) . "</label></span>", $id, $field_id, $zip_value, self::$tab_index++, $disabled_text, $field_id); if (IS_ADMIN || !$hide_country) { $style = $hide_country ? "style='display:none;'" : ""; $country = sprintf("<span class='ginput_right{$class_suffix}' id='" . $field_id . "_6_container' {$style}><select name='input_%d.6' id='%s_6' tabindex='%d' %s>%s</select><label for='%s_6' id='" . $field_id . "_6_label'>" . apply_filters("gform_address_country", __("Country", "gravityforms"), $form_id) . "</label></span>", $id, $field_id, self::$tab_index++, $disabled_text, $country_list, $field_id); } else { $country = sprintf("<input type='hidden' class='gform_hidden' name='input_%d.6' id='%s_6' value='%s'/>", $id, $field_id, $country_value); } return "<div class='ginput_complex{$class_suffix} ginput_container' id='{$field_id}'>" . $street_address . $street_address2 . $city . $state . $zip . $country . "</div>"; case "date": if (!empty($post_link)) { return $post_link; } $format = empty($field["dateFormat"]) ? "mdy" : esc_attr($field["dateFormat"]); if (IS_ADMIN && RG_CURRENT_VIEW != "entry") { $datepicker_display = $field["dateType"] == "datefield" ? "none" : "inline"; $dropdown_display = $field["dateType"] == "datefield" ? "inline" : "none"; $icon_display = $field["calendarIconType"] == "calendar" ? "inline" : "none"; $month_field = "<div class='gfield_date_month ginput_date' id='gfield_input_date_month' style='display:{$dropdown_display}'><input name='ginput_month' type='text' disabled='disabled'/><label>" . __("MM", "gravityforms") . "</label></div>"; $day_field = "<div class='gfield_date_day ginput_date' id='gfield_input_date_day' style='display:{$dropdown_display}'><input name='ginput_day' type='text' disabled='disabled'/><label>" . __("DD", "gravityforms") . "</label></div>"; $year_field = "<div class='gfield_date_year ginput_date' id='gfield_input_date_year' style='display:{$dropdown_display}'><input type='text' name='ginput_year' disabled='disabled'/><label>" . __("YYYY", "gravityforms") . "</label></div>"; $field_string = "<div class='ginput_container' id='gfield_input_datepicker' style='display:{$datepicker_display}'><input name='ginput_datepicker' type='text' /><img src='" . GFCommon::get_base_url() . "/images/calendar.png' id='gfield_input_datepicker_icon' style='display:{$icon_display}'/></div>"; $field_string .= $field["dateFormat"] == "dmy" ? $day_field . $month_field . $year_field : $month_field . $day_field . $year_field; return $field_string; } else { $date_info = GFCommon::parse_date($value, $format); if ($field["dateType"] == "datefield") { if ($format == "mdy") { $field_str = sprintf("<div class='clear-multi'><div class='gfield_date_month ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.1' value='%s' tabindex='%d' %s/><label for='%s.1'>" . __("MM", "gravityforms") . "</label></div>", $field_id, $id, $field_id, $date_info["month"], self::$tab_index++, $disabled_text, $field_id); $field_str .= sprintf("<div class='gfield_date_day ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.2' value='%s' tabindex='%d' %s/><label for='%s.2'>" . __("DD", "gravityforms") . "</label></div>", $field_id, $id, $field_id, $date_info["day"], self::$tab_index++, $disabled_text, $field_id); } else { $field_str = sprintf("<div class='clear-multi'><div class='gfield_date_day ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.2' value='%s' tabindex='%d' %s/><label for='%s.2'>" . __("DD", "gravityforms") . "</label></div>", $field_id, $id, $field_id, $date_info["day"], self::$tab_index++, $disabled_text, $field_id); $field_str .= sprintf("<div class='gfield_date_month ginput_container' id='%s'><input type='text' maxlength='2' name='input_%d[]' id='%s.1' value='%s' tabindex='%d' %s/><label for='%s.1'>" . __("MM", "gravityforms") . "</label></div>", $field_id, $id, $field_id, $date_info["month"], self::$tab_index++, $disabled_text, $field_id); } $field_str .= sprintf("<div class='gfield_date_year ginput_container' id='%s'><input type='text' maxlength='4' name='input_%d[]' id='%s.3' value='%s' tabindex='%d' %s/><label for='%s.3'>" . __("YYYY", "gravityforms") . "</label></div></div>", $field_id, $id, $field_id, $date_info["year"], self::$tab_index++, $disabled_text, $field_id); return $field_str; } else { $value = GFCommon::date_display($value, $format); $icon_class = $field["calendarIconType"] == "none" ? "datepicker_no_icon" : "datepicker_with_icon"; $icon_url = empty($field["calendarIconUrl"]) ? GFCommon::get_base_url() . "/images/calendar.png" : $field["calendarIconUrl"]; return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='text' value='%s' class='datepicker %s %s %s' tabindex='%d' %s/>%s</div><input type='hidden' id='gforms_calendar_icon_{$field_id}' class='gform_hidden' value='{$icon_url}'/>", $id, $field_id, esc_attr($value), esc_attr($class), $format, $icon_class, self::$tab_index++, $disabled_text, $datepicker); } } case "time": if (!empty($post_link)) { return $post_link; } if (!is_array($value) && !empty($value)) { preg_match('/^(\\d*):(\\d*) (.*)$/', $value, $matches); $hour = esc_attr($matches[1]); $minute = esc_attr($matches[2]); $am_selected = $matches[3] == "am" ? "selected='selected'" : ""; $pm_selected = $matches[3] == "pm" ? "selected='selected'" : ""; } else { $hour = esc_attr($value[0]); $minute = esc_attr($value[1]); $am_selected = $value[2] == "am" ? "selected='selected'" : ""; $pm_selected = $value[2] == "pm" ? "selected='selected'" : ""; } return sprintf("<div class='clear-multi'><div class='gfield_time_hour ginput_container' id='%s'><input type='text' name='input_%d[]' id='%s.1' value='%s' tabindex='%d' %s/> : <label for='%s.1'>" . __("HH", "gravityforms") . "</label></div><div class='gfield_time_minute'><input type='text' name='input_%d[]' id='%s.2' value='%s' tabindex='%d' %s/><label for='%s.2'>" . __("MM", "gravityforms") . "</label></div><div class='gfield_time_ampm'><select name='input_%d[]' id='%s.3' tabindex='%d' %s><option value='am' %s>" . __("AM", "gravityforms") . "</option><option value='pm' %s>" . __("PM", "gravityforms") . "</option></select></div></div>", $field_id, $id, $field_id, $hour, self::$tab_index++, $disabled_text, $field_id, $id, $field_id, $minute, self::$tab_index++, $disabled_text, $field_id, $id, $field_id, self::$tab_index++, $disabled_text, $am_selected, $pm_selected); case "fileupload": $upload = sprintf("<input name='input_%d' id='%s' type='file' value='%s' size='20' class='%s' tabindex='%d' %s/>", $id, $field_id, esc_attr($value), esc_attr($class), self::$tab_index++, $disabled_text); if (IS_ADMIN && !empty($value)) { $value = esc_attr($value); $preview = sprintf("<div id='preview_%d'><a href='%s' target='_blank' alt='%s' title='%s'>%s</a><a href='%s' target='_blank' alt='" . __("Download file", "gravityforms") . "' title='" . __("Download file", "gravityforms") . "'><img src='%s' style='margin-left:10px;'/></a><a href='javascript:void(0);' alt='" . __("Delete file", "gravityforms") . "' title='" . __("Delete file", "gravityforms") . "' onclick='DeleteFile(%d,%d);' ><img src='%s' style='margin-left:10px;'/></a></div>", $id, $value, $value, $value, GFCommon::truncate_url($value), $value, GFCommon::get_base_url() . "/images/download.png", $lead_id, $id, GFCommon::get_base_url() . "/images/delete.png"); return $preview . "<div id='upload_{$id}' style='display:none;'>{$upload}</div>"; } else { return "<div class='ginput_container'>{$upload}</div>"; } case "captcha": if (!function_exists("recaptcha_get_html")) { require_once GFCommon::get_base_path() . '/recaptchalib.php'; } $theme = empty($field["captchaTheme"]) ? "red" : esc_attr($field["captchaTheme"]); $publickey = get_option("rg_gforms_captcha_public_key"); $privatekey = get_option("rg_gforms_captcha_private_key"); if (IS_ADMIN) { if (empty($publickey) || empty($privatekey)) { return "<div class='captcha_message'>" . __("To use the reCaptcha field you must first do the following:", "gravityforms") . "</div><div class='captcha_message'>1 - <a href='https://admin.recaptcha.net/recaptcha/createsite/?app=php' target='_blank'>" . __(sprintf("Sign up%s for a free reCAPTCHA account", "</a>"), "gravityforms") . "</div><div class='captcha_message'>2 - " . __(sprintf("Enter your reCAPTCHA keys in the %ssettings page%s", "<a href='?page=gf_settings'>", "</a>"), "gravityforms") . "</div>"; } else { return "<div><img class='gfield_captcha' src='" . GFCommon::get_base_url() . "/images/captcha_{$theme}.jpg' alt='reCAPTCHA' title='reCAPTCHA'/></div>"; } } else { $language = empty($field["captchaLanguage"]) ? "en" : esc_attr($field["captchaLanguage"]); $options = "<script type='text/javascript'>var RecaptchaOptions = {theme : '{$theme}',tabindex : " . self::$tab_index++ . ", lang : '{$language}'};</script>"; $is_ssl = !empty($_SERVER['HTTPS']); return $options . "<div class='ginput_container' id='{$field_id}'>" . recaptcha_get_html($publickey, null, $is_ssl) . "</div>"; } break; } }
private static function prepare_value($form, $field, $value, $input_name, $lead_id) { $form_id = $form["id"]; $input_type = self::get_input_type($field); switch ($input_type) { case "total": $lead = RGFormsModel::get_lead($lead_id); $value = GFCommon::get_order_total($form, $lead); break; case "post_category": $cat = get_category($value); $value = !empty($cat) ? $cat->name . ":" . $value : ""; break; case "phone": if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) { $value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]); } break; case "time": if (!is_array($value) && !empty($value)) { preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches); $value = array(); $value[0] = $matches[1]; $value[1] = $matches[2]; $value[2] = rgar($matches, 3); } $hour = empty($value[0]) ? "0" : strip_tags($value[0]); $minute = empty($value[1]) ? "0" : strip_tags($value[1]); $ampm = strip_tags(rgar($value, 2)); if (!empty($ampm)) { $ampm = " {$ampm}"; } if (!(empty($hour) && empty($minute))) { $value = sprintf("%02d:%02d%s", $hour, $minute, $ampm); } else { $value = ""; } break; case "date": $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"]; $date_info = GFCommon::parse_date($value, $format); if (!empty($date_info)) { $value = sprintf("%d-%02d-%02d", $date_info["year"], $date_info["month"], $date_info["day"]); } else { $value = ""; } break; case "post_image": $url = self::get_fileupload_value($form_id, $input_name); $image_title = isset($_POST["{$input_name}_1"]) ? strip_tags($_POST["{$input_name}_1"]) : ""; $image_caption = isset($_POST["{$input_name}_4"]) ? strip_tags($_POST["{$input_name}_4"]) : ""; $image_description = isset($_POST["{$input_name}_7"]) ? strip_tags($_POST["{$input_name}_7"]) : ""; $value = !empty($url) ? $url . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : ""; break; case "fileupload": $value = self::get_fileupload_value($form_id, $input_name); break; case "number": $value = GFCommon::clean_number($value, rgar($field, "numberFormat")); break; case "website": if ($value == "http://") { $value = ""; } break; case "list": if (GFCommon::is_empty_array($value)) { $value = ""; } else { $value = self::create_list_array($field, $value); $value = serialize($value); } break; case "radio": if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') { $value = rgpost("input_{$field['id']}_other"); } break; case "multiselect": $value = empty($value) ? "" : implode(",", $value); break; case "creditcard": //saving last 4 digits of credit card list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3); if ($input_id == "1") { $value = str_replace(" ", "", $value); $card_number_length = strlen($value); $value = substr($value, -4, 4); $value = str_pad($value, $card_number_length, "X", STR_PAD_LEFT); } else { if ($input_id == "4") { $card_number = rgpost("input_{$field_id_token}_1"); $card_type = GFCommon::get_card_type($card_number); $value = $card_type ? $card_type["name"] : ""; } else { $value = ""; } } break; default: //allow HTML for certain field types $allow_html = in_array($field["type"], array("post_custom_field", "post_title", "post_content", "post_excerpt", "post_tags")) || in_array($input_type, array("checkbox", "radio")) ? true : false; $allowable_tags = apply_filters("gform_allowable_tags_{$form_id}", apply_filters("gform_allowable_tags", $allow_html, $field, $form_id), $field, $form_id); if ($allowable_tags !== true) { $value = strip_tags($value, $allowable_tags); } break; } //do not save price fields with blank price if (rgar($field, "enablePrice")) { $ary = explode("|", $value); $label = count($ary) > 0 ? $ary[0] : ""; $price = count($ary) > 1 ? $ary[1] : ""; $is_empty = strlen(trim($price)) <= 0; if ($is_empty) { $value = ""; } } return $value; }
private static function prepare_value($form_id, $field, $value, $input_name) { switch (self::get_input_type($field)) { case "post_category": $cat = get_category($value); $value = $cat->name; break; case "post_title": case "post_content": case "post_excerpt": case "post_tags": case "post_custom_fields": case "post_image": $value = stripslashes($value); break; case "phone": if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) { $value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]); } break; case "time": if (!is_array($value) && !empty($value)) { preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches); $value = array(); $value[0] = $matches[1]; $value[1] = $matches[2]; $value[2] = $matches[3]; } $hour = empty($value[0]) ? "0" : strip_tags($value[0]); $minute = empty($value[1]) ? "0" : strip_tags($value[1]); $ampm = strip_tags($value[2]); if (!(empty($hour) && empty($minute))) { $value = sprintf("%02d:%02d %s", $hour, $minute, $ampm); } else { $value = ""; } break; case "date": $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"]; $date_info = GFCommon::parse_date($value, $format); if (!empty($date_info)) { $value = sprintf("%d-%02d-%02d", $date_info["year"], $date_info["month"], $date_info["day"]); } else { $value = ""; } break; case "fileupload": $value = self::upload_file($form_id, $_FILES[$input_name]); break; case "number": $value = GFCommon::clean_number($value); break; default: $value = strip_tags(stripslashes($value)); break; } return $value; }