function post_to_third_party($entry, $form) { $post_url = 'http://thirdparty.com'; $body = array('first_name' => rgar($entry, '1.3'), 'last_name' => rgar($entry, '1.6'), 'message' => rgar($entry, '3')); $request = new WP_Http(); $response = $request->post($post_url, array('body' => $body)); }
/** * Loads the matching meta data for the currently set form id * @return boolean true on success and false on failure */ public function load() { if (!defined('WPINC') || !$this->_post_id || !class_exists('GFAPI')) { return false; } $lead = \GFAPI::get_entry($this->_post_id); $form = \GFAPI::get_form($lead['form_id']); $values = array(); foreach ($form['fields'] as $field) { if (isset($field["inputs"]) && is_array($field['inputs'])) { foreach ($field['inputs'] as $input) { // Extract best label $key = $input['label'] ? $input['label'] : \GFCommon::get_label($field, (string) $input["id"]); // Redundant formatting $key = strtolower(str_replace(array(' '), array('_'), $key)); $value = isset($lead[(string) $input['id']]) ? $lead[(string) $input['id']] : ""; $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES); } } elseif (!rgar($field, 'displayOnly')) { // Extract best label $key = isset($field['adminLabel']) && $field['adminLabel'] != "" ? $field['adminLabel'] : ($field['label'] ? $field['label'] : \GFCommon::get_label($field)); // More redundant formatting $key = strtolower(str_replace(array(' '), array('_'), $key)); $value = isset($lead[$field['id']]) ? $lead[$field['id']] : ""; $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES); } } try { $this->assign($values); } catch (Exception $e) { $error = $e->getMessage(); } return true; }
function gform_column_splits($content, $field, $value, $lead_id, $form_id) { if (IS_ADMIN) { return $content; } // only modify HTML on the front end $form = RGFormsModel::get_form_meta($form_id, true); $form_class = array_key_exists('cssClass', $form) ? $form['cssClass'] : ''; $form_classes = preg_split('/[\\n\\r\\t ]+/', $form_class, -1, PREG_SPLIT_NO_EMPTY); $fields_class = array_key_exists('cssClass', $field) ? $field['cssClass'] : ''; $field_classes = preg_split('/[\\n\\r\\t ]+/', $fields_class, -1, PREG_SPLIT_NO_EMPTY); if (!is_admin()) { // multi-column form functionality if ($field['type'] == 'section') { $form = RGFormsModel::get_form_meta($form_id, true); // check for the presence of multi-column form classes $form_class = explode(' ', $form['cssClass']); $form_class_matches = array_intersect($form_class, array('two-column', 'three-column')); // check for the presence of section break column classes $field_class = explode(' ', $field['cssClass']); $field_class_matches = array_intersect($field_class, array('gform_column')); // if field is a column break in a multi-column form, perform the list split if (!empty($form_class_matches) && !empty($field_class_matches)) { // make sure to target only multi-column forms // retrieve the form's field list classes for consistency $form = RGFormsModel::add_default_properties($form); $description_class = rgar($form, 'descriptionPlacement') == 'above' ? 'description_above' : 'description_below'; // close current field's li and ul and begin a new list with the same form field list classes return '</li></ul><ul class="gform_fields ' . $form['labelPlacement'] . ' ' . $description_class . ' ' . $field['cssClass'] . '"><li class="gfield gsection empty">'; } } } return $content; }
/** * Update the post categories based on all post category fields * * @since 1.17 * * @param array $form Gravity Forms form array * @param int $entry_id Numeric ID of the entry that was updated * * @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure. false if there are no post category fields or connected post. */ public function set_post_categories($form = array(), $entry_id = 0) { $entry = GFAPI::get_entry($entry_id); $post_id = rgar($entry, 'post_id'); if (empty($post_id)) { return false; } $return = false; $post_category_fields = GFAPI::get_fields_by_type($form, 'post_category'); if ($post_category_fields) { $updated_categories = array(); foreach ($post_category_fields as $field) { // Get the value of the field, including $_POSTed value $field_cats = RGFormsModel::get_field_value($field); $field_cats = is_array($field_cats) ? array_values($field_cats) : (array) $field_cats; $field_cats = gv_map_deep($field_cats, 'intval'); $updated_categories = array_merge($updated_categories, array_values($field_cats)); } // Remove `0` values from intval() $updated_categories = array_filter($updated_categories); /** * @filter `gravityview/edit_entry/post_categories/append` Should post categories be added to or replaced? * @since 1.17 * @param bool $append If `true`, don't delete existing categories, just add on. If `false`, replace the categories with the submitted categories. Default: `false` */ $append = apply_filters('gravityview/edit_entry/post_categories/append', false); $return = wp_set_post_categories($post_id, $updated_categories, $append); } return $return; }
function validate($posted_values) { $valid_key = true; $terms_accepted = true; $license_key = rgar($posted_values, 'license_key'); if (empty($license_key)) { $message = esc_html__('Please enter a valid license key.', 'gravityflow') . '</span>'; $this->set_field_validation_result('license_key', $message); $valid_key = false; } else { $license_info = gravity_flow()->activate_license($license_key); if (empty($license_info) || $license_info->license !== 'valid') { $message = " <i class='fa fa-times gf_keystatus_invalid'></i> <span class='gf_keystatus_invalid_text'>" . __('Invalid or Expired Key : Please make sure you have entered the correct value and that your key is not expired.', 'gravityflow') . '</span>'; $this->set_field_validation_result('license_key', $message); $valid_key = false; } } $accept_terms = rgar($posted_values, 'accept_terms'); if (!$valid_key && !$accept_terms) { $this->set_field_validation_result('accept_terms', __('Please accept the terms', 'gravityflow')); $terms_accepted = false; } $valid = $valid_key || !$valid_key && $terms_accepted; return $valid; }
/** * 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 function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) { $use_value = $modifier == 'value'; $use_price = in_array($modifier, array('price', 'currency')); $format_currency = $modifier == 'currency'; if (is_array($raw_value) && (string) intval($input_id) != $input_id) { $items = array($input_id => $value); //float input Ids. (i.e. 4.1 ). Used when targeting specific checkbox items } elseif (is_array($raw_value)) { $items = $raw_value; } else { $items = array($input_id => $raw_value); } $ary = array(); foreach ($items as $input_id => $item) { if ($use_value) { list($val, $price) = rgexplode('|', $item, 2); } elseif ($use_price) { list($name, $val) = rgexplode('|', $item, 2); if ($format_currency) { $val = GFCommon::to_money($val, rgar($entry, 'currency')); } } elseif ($this->type == 'post_category') { $use_id = strtolower($modifier) == 'id'; $item_value = GFCommon::format_post_category($item, $use_id); $val = RGFormsModel::is_field_hidden($form, $this, array(), $entry) ? '' : $item_value; } else { $val = RGFormsModel::is_field_hidden($form, $this, array(), $entry) ? '' : RGFormsModel::get_choice_text($this, $raw_value, $input_id); } $ary[] = GFCommon::format_variable_value($val, $url_encode, $esc_html, $format); } return GFCommon::implode_non_blank(', ', $ary); }
/** * Add pending referral * * @access public * @uses GFFormsModel::get_lead() * @uses GFCommon::get_product_fields() * @uses GFCommon::to_number() * * @param array $entry * @param array $form */ public function add_pending_referral($entry, $form) { if ($this->was_referred()) { // Do some craziness to determine the price (this should be easy but is not) $desc = ''; $entry = GFFormsModel::get_lead($entry['id']); $products = GFCommon::get_product_fields($form, $entry); $total = 0; foreach ($products['products'] as $key => $product) { $desc .= $product['name']; if ($key + 1 < count($products)) { $description .= ', '; } $price = GFCommon::to_number($product['price']); if (is_array(rgar($product, 'options'))) { $count = sizeof($product['options']); $index = 1; foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); } } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; } $total += floatval($products['shipping']['price']); $referral_total = $this->calculate_referral_amount($total, $entry['id']); $this->insert_pending_referral($referral_total, $entry['id'], $desc); } }
/** * If a form has list fields, add the columns to the field picker * * @since 1.17 * * @param array $fields Associative array of fields, with keys as field type * @param array $form GF Form array * @param bool $include_parent_field Whether to include the parent field when getting a field with inputs * * @return array $fields with list field columns added, if exist. Unmodified if form has no list fields. */ function add_form_fields($fields = array(), $form = array(), $include_parent_field = true) { $list_fields = GFAPI::get_fields_by_type($form, 'list'); // Add the list columns foreach ($list_fields as $list_field) { if (empty($list_field->enableColumns)) { continue; } $list_columns = array(); foreach ((array) $list_field->choices as $key => $input) { $input_id = sprintf('%d.%d', $list_field->id, $key); // {field_id}.{column_key} $list_columns[$input_id] = array('label' => rgar($input, 'text'), 'customLabel' => '', 'parent' => $list_field, 'type' => rgar($list_field, 'type'), 'adminLabel' => rgar($list_field, 'adminLabel'), 'adminOnly' => rgar($list_field, 'adminOnly')); } // If there are columns, add them under the parent field if (!empty($list_columns)) { $index = array_search($list_field->id, array_keys($fields)) + 1; /** * Merge the $list_columns into the $fields array at $index * @see https://stackoverflow.com/a/1783125 */ $fields = array_slice($fields, 0, $index, true) + $list_columns + array_slice($fields, $index, null, true); } unset($list_columns, $index, $input_id); } return $fields; }
/** * Displays the tooltip * * @global $__gf_tooltips * * @param string $name The name of the tooltip to be displayed * @param string $css_class Optional. The CSS class to apply toi the element. Defaults to empty string. * @param bool $return Optional. If the tooltip should be returned instead of output. Defaults to false (output) * * @return string */ function gform_tooltip($name, $css_class = '', $return = false) { global $__gf_tooltips; //declared as global to improve WPML performance $css_class = empty($css_class) ? 'tooltip' : $css_class; /** * Filters the tooltips available * * @param array $__gf_tooltips Array containing the available tooltips */ $__gf_tooltips = apply_filters('gform_tooltips', $__gf_tooltips); //AC: the $name parameter is a key when it has only one word. Maybe try to improve this later. $parameter_is_key = count(explode(' ', $name)) == 1; $tooltip_text = $parameter_is_key ? rgar($__gf_tooltips, $name) : $name; $tooltip_class = isset($__gf_tooltips[$name]) ? "tooltip_{$name}" : ''; $tooltip_class = esc_attr($tooltip_class); if (empty($tooltip_text)) { return ''; } $tooltip = "<a href='#' onclick='return false;' onkeypress='return false;' class='gf_tooltip " . esc_attr($css_class) . " {$tooltip_class}' title='" . esc_attr($tooltip_text) . "'><i class='fa fa-question-circle'></i></a>"; if ($return) { return $tooltip; } else { echo $tooltip; } }
/** * Acquirrer field input * * @param string $field_content * @param string $field * @param string $value * @param string $lead_id * @param string $form_id */ public static function acquirer_field_input($field_content, $field, $value, $lead_id, $form_id) { $type = RGFormsModel::get_input_type($field); if (Pronamic_WP_Pay_Extensions_GravityForms_IssuerDropDown::TYPE === $type) { $id = $field['id']; $field_id = IS_ADMIN || 0 === $form_id ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $class_suffix = RG_CURRENT_VIEW === 'entry' ? '_admin' : ''; $size = rgar($field, 'size'); $class = $size . $class_suffix; $css_class = trim(esc_attr($class) . ' gfield_ideal_acquirer_select'); $tab_index = GFCommon::get_tabindex(); $disabled_text = IS_ADMIN && 'entry' !== RG_CURRENT_VIEW ? "disabled='disabled'" : ''; $html = ''; $feed = get_pronamic_gf_pay_conditioned_feed_by_form_id($form_id, true); /** * Developing warning: * Don't use single quotes in the HTML you output, it is buggy in combination with SACK */ if (IS_ADMIN) { if (null === $feed) { $html .= sprintf("<a class='ideal-edit-link' href='%s' target='_blank'>%s</a>", add_query_arg('post_type', 'pronamic_pay_gf', admin_url('post-new.php')), __('Create iDEAL feed', 'pronamic_ideal')); } else { $html .= sprintf("<a class='ideal-edit-link' href='%s' target='_blank'>%s</a>", get_edit_post_link($feed->id), __('Edit iDEAL feed', 'pronamic_ideal')); } } $html_input = ''; $html_error = ''; if (null !== $feed) { $gateway = Pronamic_WP_Pay_Plugin::get_gateway($feed->config_id); if ($gateway) { $issuer_field = $gateway->get_issuer_field(); $error = $gateway->get_error(); if (is_wp_error($error)) { $html_error .= Pronamic_WP_Pay_Plugin::get_default_error_message(); $html_error .= '<br /><em>' . $error->get_error_message() . '</em>'; } elseif ($issuer_field) { $choices = $issuer_field['choices']; $options = Pronamic_WP_HTML_Helper::select_options_grouped($choices, $value); // Double quotes are not working, se we replace them with an single quote $options = str_replace('"', '\'', $options); $html_input = ''; $html_input .= sprintf("<select name='input_%d' id='%s' class='%s' %s %s>", $id, $field_id, $css_class, $tab_index, $disabled_text); $html_input .= sprintf('%s', $options); $html_input .= sprintf('</select>'); } } } if ($html_error) { $html .= sprintf("<div class='gfield_description validation_message'>"); $html .= sprintf('%s', $html_error); $html .= sprintf('</div>'); } else { $html .= sprintf("<div class='ginput_container ginput_ideal'>"); $html .= sprintf('%s', $html_input); $html .= sprintf('</div>'); } $field_content = $html; } return $field_content; }
public function get_field_input($form, $value = '', $entry = null) { $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); if (is_array($value)) { $value = array_values($value); } $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}"; $form_id = ($is_entry_detail || $is_form_editor) && empty($form_id) ? rgget('id') : $form_id; $size = $this->size; $disabled_text = $is_form_editor ? "disabled='disabled'" : ''; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $this->emailConfirmEnabled ? '' : $size . $class_suffix; //Size only applies when confirmation is disabled $form_sub_label_placement = rgar($form, 'subLabelPlacement'); $field_sub_label_placement = $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'" : ''; $html_input_type = RGFormsModel::is_html5_enabled() ? 'email' : 'text'; $enter_email_field_input = GFFormsModel::get_input($this, $this->id . ''); $confirm_field_input = GFFormsModel::get_input($this, $this->id . '.2'); $enter_email_label = rgar($enter_email_field_input, 'customLabel') != '' ? $enter_email_field_input['customLabel'] : __('Enter Email', 'gravityforms'); $enter_email_label = apply_filters("gform_email_{$form_id}", apply_filters('gform_email', $enter_email_label, $form_id), $form_id); $confirm_email_label = rgar($confirm_field_input, 'customLabel') != '' ? $confirm_field_input['customLabel'] : __('Confirm Email', 'gravityforms'); $confirm_email_label = apply_filters("gform_email_confirm_{$form_id}", apply_filters('gform_email_confirm', $confirm_email_label, $form_id), $form_id); $single_placeholder_attribute = $this->get_field_placeholder_attribute(); $enter_email_placeholder_attribute = $this->get_input_placeholder_attribute($enter_email_field_input); $confirm_email_placeholder_attribute = $this->get_input_placeholder_attribute($confirm_field_input); if ($is_form_editor) { $single_style = $this->emailConfirmEnabled ? "style='display:none;'" : ''; $confirm_style = $this->emailConfirmEnabled ? '' : "style='display:none;'"; if ($is_sub_label_above) { return "<div class='ginput_container ginput_single_email' {$single_style}>\n <input name='input_{$id}' type='{$html_input_type}' class='" . esc_attr($class) . "' disabled='disabled' {$single_placeholder_attribute} />\n <div class='gf_clear gf_clear_complex'></div>\n </div>\n <div class='ginput_complex ginput_container ginput_confirm_email' {$confirm_style} id='{$field_id}_container'>\n <span id='{$field_id}_container' class='ginput_left'>\n <label for='{$field_id}' {$sub_label_class_attribute}>{$enter_email_label}</label>\n <input class='{$class}' type='text' name='input_{$id}' id='{$field_id}' disabled='disabled' {$enter_email_placeholder_attribute}/>\n </span>\n <span id='{$field_id}_2_container' class='ginput_right'>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$confirm_email_label}</label>\n <input class='{$class}' type='text' name='input_{$id}_2' id='{$field_id}_2' disabled='disabled' {$confirm_email_placeholder_attribute}/>\n </span>\n <div class='gf_clear gf_clear_complex'></div>\n </div>"; } else { return "<div class='ginput_container ginput_single_email' {$single_style}>\n <input class='{$class}' name='input_{$id}' type='{$html_input_type}' class='" . esc_attr($class) . "' disabled='disabled' {$single_placeholder_attribute}/>\n <div class='gf_clear gf_clear_complex'></div>\n </div>\n <div class='ginput_complex ginput_container ginput_confirm_email' {$confirm_style} id='{$field_id}_container'>\n <span id='{$field_id}_container' class='ginput_left'>\n <input class='{$class}' type='text' name='input_{$id}' id='{$field_id}' disabled='disabled' {$enter_email_placeholder_attribute}/>\n <label for='{$field_id}' {$sub_label_class_attribute}>{$enter_email_label}</label>\n </span>\n <span id='{$field_id}_2_container' class='ginput_right'>\n <input class='{$class}' type='text' name='input_{$id}_2' id='{$field_id}_2' disabled='disabled' {$confirm_email_placeholder_attribute}/>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$confirm_email_label}</label>\n </span>\n <div class='gf_clear gf_clear_complex'></div>\n </div>"; } } else { $logic_event = $this->get_conditional_logic_event('keyup'); if ($this->emailConfirmEnabled && !$is_entry_detail) { $first_tabindex = $this->get_tabindex(); $last_tabindex = $this->get_tabindex(); $email_value = is_array($value) ? esc_attr($value[0]) : $value; $confirmation_value = is_array($value) ? esc_attr($value[1]) : rgpost('input_' . $this->id . '_2'); $confirmation_disabled = $is_entry_detail ? "disabled='disabled'" : $disabled_text; if ($is_sub_label_above) { return "<div class='ginput_complex ginput_container' id='{$field_id}_container'>\n <span id='{$field_id}_container' class='ginput_left'>\n <label for='{$field_id}'>" . $enter_email_label . "</label>\n <input class='{$class}' type='{$html_input_type}' name='input_{$id}' id='{$field_id}' value='" . $email_value . "' {$first_tabindex} {$logic_event} {$disabled_text} {$enter_email_placeholder_attribute}/>\n </span>\n <span id='{$field_id}_2_container' class='ginput_right'>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$confirm_email_label}</label>\n <input class='{$class}' type='{$html_input_type}' name='input_{$id}_2' id='{$field_id}_2' value='" . $confirmation_value . "' {$last_tabindex} {$confirmation_disabled} {$confirm_email_placeholder_attribute}/>\n </span>\n <div class='gf_clear gf_clear_complex'></div>\n </div>"; } else { return "<div class='ginput_complex ginput_container' id='{$field_id}_container'>\n <span id='{$field_id}_container' class='ginput_left'>\n <input class='{$class}' type='{$html_input_type}' name='input_{$id}' id='{$field_id}' value='" . $email_value . "' {$first_tabindex} {$logic_event} {$disabled_text} {$enter_email_placeholder_attribute}/>\n <label for='{$field_id}' {$sub_label_class_attribute}>{$enter_email_label}</label>\n </span>\n <span id='{$field_id}_2_container' class='ginput_right'>\n <input class='{$class}' type='{$html_input_type}' name='input_{$id}_2' id='{$field_id}_2' value='" . $confirmation_value . "' {$last_tabindex} {$confirmation_disabled} {$confirm_email_placeholder_attribute}/>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$confirm_email_label}</label>\n </span>\n <div class='gf_clear gf_clear_complex'></div>\n </div>"; } } else { $tabindex = $this->get_tabindex(); $value = esc_attr($value); $class = esc_attr($class); return "<div class='ginput_container'>\n <input name='input_{$id}' id='{$field_id}' type='{$html_input_type}' value='{$value}' class='{$class}' {$tabindex} {$logic_event} {$disabled_text} {$single_placeholder_attribute}/>\n </div>"; } } }
function column_is_active($item) { $is_active = intval(rgar($item, "is_active")); $src = GFCommon::get_base_url() . "/images/active{$is_active}.png"; $title = $is_active ? __("Active", "gravityforms") : __("Inactive", "gravityforms"); $img = sprintf("<img src=\"{$src}\" class=\"toggle_active\" title=\"{$title}\" data-feed-id=\"%s\" style=\"cursor:pointer\";/>", $item['id']); return $img; }
/** * @param $array * @param $name * * @return string */ function rgars($array, $name) { $names = explode('/', $name); $val = $array; foreach ($names as $current_name) { $val = rgar($val, $current_name); } return $val; }
/** * Check if the form has a text field with a Custom CSS Class that contains 'helpscout-docs' * * @param array $form * * @return bool True: yes, it does. False: nope. */ private function has_docs_field($form) { $text_fields = GFCommon::get_fields_by_type($form, 'text'); foreach ($text_fields as $text_field) { if (strpos(rgar($text_field, 'cssClass'), self::field_css_class) !== false) { return true; } } return false; }
public function form_button_settings($settings, $form) { $settings['Form Basics'] = array_merge($settings['Form Basics'], array('form_terms_pdf' => '<tr> <th><label for="terms_pdf">Terms PDF</label></th> <td><input type="text" value="' . rgar($form, 'terms_pdf') . '" name="terms_pdf" class="fieldwidth-3"></td> </tr>', 'form_terms_title' => '<tr> <th><label for="terms_title">Terms Title</label></th> <td><input type="text" value="' . rgar($form, 'terms_title') . '" name="terms_title" class="fieldwidth-3"></td> </tr>')); return $settings; }
public static function add_form_setting($settings, $form) { $current = rgar($form, 'enable_validation'); $checked = !empty($current) ? 'checked="checked"' : ''; $settings['Form Options']['enable_validation'] = ' <tr> <th>Javascript Validation <a href="#" onclick="return false;" class="tooltip tooltip_form_animation" tooltip="<h6>Enable Client-side Validation</h6>Check this option to enable validation messages for the client before reloading the page."></a></th> <td><input type="checkbox" value="1" ' . $checked . ' name="enable_validation"> <label for="enable_validation">' . __('Validate forms before submission', 'gravity-forms-js-validate') . '</label></td> </tr>'; return $settings; }
function gform_create_zendesk_ticket($entry, $form) { $binaryFile = file_get_contents(rgar($entry, '15')); $ext = pathinfo(rgar($entry, '15'), PATHINFO_EXTENSION); // Upload field ID $upload = curlUpload("/uploads.json", $binaryFile, 'upload.' . $ext); // Attachments will have the prettyname screenshot.[$ext] $token = $upload['upload']['token']; $create = json_encode(array('ticket' => array('subject' => rgar($entry, '5'), 'priority' => 'normal', 'comment' => array('body' => rgar($entry, '6'), 'uploads' => $token), 'requester' => array('name' => rgar($entry, '2.3') . ' ' . rgar($entry, '2.6'), 'email' => rgar($entry, '4'))))); return curlWrap("/tickets.json", $create, "POST"); }
public static function add_form_setting($settings, $form) { $current = rgar($form, 'enable_sisyphus'); $checked = !empty($current) ? 'checked="checked"' : ''; $settings['Form Options']['enable_sisyphus'] = ' <tr> <th>Sisyphus <a href="#" onclick="return false;" class="tooltip tooltip_form_animation" tooltip="<h6>Enable Sisyphus Saving</h6>Check this option to enable saving forms with local storage through the Sisyphus plugin."></a></th> <td><input type="checkbox" value="1" ' . $checked . ' name="enable_sisyphus"> <label for="enable_sisyphus">' . __('Enable local saving of forms', 'gravity-forms-sisyphus') . '</label></td> </tr>'; return $settings; }
/** * Add {payment_amount} merge tag * * @since 1.16 ** * @param array $matches Array of Merge Tag matches found in text by preg_match_all * @param string $text Text to replace * @param array $form Gravity Forms form array * @param array $entry Entry array * @param bool $url_encode Whether to URL-encode output * * @return string Original text if {date_created} isn't found. Otherwise, replaced text. */ public function replace_merge_tag($matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false) { $return = $text; foreach ($matches as $match) { $full_tag = $match[0]; $modifier = isset($match[1]) ? $match[1] : false; $amount = rgar($entry, 'payment_amount'); $formatted_amount = 'raw' === $modifier ? $amount : GFCommon::to_money($amount, rgar($entry, 'currency')); $return = str_replace($full_tag, $formatted_amount, $return); } unset($formatted_amount, $amount, $full_tag, $matches); return $return; }
/** * Add {date_created} merge tag and format the values using format_date * * @since 1.16 * * @see http://docs.gravityview.co/article/331-date-created-merge-tag for usage information * * @param array $matches Array of Merge Tag matches found in text by preg_match_all * @param string $text Text to replace * @param array $form Gravity Forms form array * @param array $entry Entry array * @param bool $url_encode Whether to URL-encode output * * @return string Original text if {date_created} isn't found. Otherwise, replaced text. */ public function replace_merge_tag($matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false) { $return = $text; /** Use $this->name instead of date_created because Payment Date uses this as well*/ $date_created = rgar($entry, $this->name); foreach ($matches as $match) { $full_tag = $match[0]; $property = $match[1]; $formatted_date = GravityView_Merge_Tags::format_date($date_created, $property); $return = str_replace($full_tag, $formatted_date, $return); } return $return; }
public function get_field_input($form, $value = '', $entry = null) { $form_id = $form['id']; $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; switch ($this->captchaType) { case 'simple_captcha': $size = empty($this->simpleCaptchaSize) ? 'medium' : $this->simpleCaptchaSize; $captcha = $this->get_captcha(); $tabindex = $this->get_tabindex(); $dimensions = $is_entry_detail || $is_form_editor ? '' : "width='" . rgar($captcha, 'width') . "' height='" . rgar($captcha, 'height') . "'"; return "<div class='gfield_captcha_container'><img class='gfield_captcha' src='" . rgar($captcha, 'url') . "' alt='' {$dimensions} /><div class='gfield_captcha_input_container simple_captcha_{$size}'><input type='text' name='input_{$id}' id='{$field_id}' {$tabindex}/><input type='hidden' name='input_captcha_prefix_{$id}' value='" . rgar($captcha, 'prefix') . "' /></div></div>"; break; case 'math': $size = empty($this->simpleCaptchaSize) ? 'medium' : $this->simpleCaptchaSize; $captcha_1 = $this->get_math_captcha(1); $captcha_2 = $this->get_math_captcha(2); $captcha_3 = $this->get_math_captcha(3); $tabindex = $this->get_tabindex(); $dimensions = $is_entry_detail || $is_form_editor ? '' : "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='{$field_id}' {$tabindex}/><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($this->captchaTheme) ? 'red' : esc_attr($this->captchaTheme); $publickey = get_option('rg_gforms_captcha_public_key'); $privatekey = get_option('rg_gforms_captcha_private_key'); if ($is_entry_detail || $is_form_editor) { 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='http://www.google.com/recaptcha' target='_blank'>" . sprintf(__('Sign up%s for a free reCAPTCHA account', 'gravityforms'), '</a>') . "</div><div class='captcha_message'>2 - " . sprintf(__('Enter your reCAPTCHA keys in the %ssettings page%s', 'gravityforms'), "<a href='?page=gf_settings'>", '</a>') . '</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($this->captchaLanguage) ? 'en' : esc_attr($this->captchaLanguage); if (empty(GFCommon::$tab_index)) { GFCommon::$tab_index = 1; } $tabindex = GFCommon::$tab_index; $tabindex2 = GFCommon::$tab_index++; $options = "<script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . " var RecaptchaOptions = {theme : '{$theme}'}; if(parseInt('{$tabindex}') > 0) {RecaptchaOptions.tabindex = {$tabindex2};}" . apply_filters('gform_recaptcha_init_script', '', $form_id, $this) . apply_filters('gform_cdata_close', '') . '</script>'; $is_ssl = !empty($_SERVER['HTTPS']); return $options . "<div class='ginput_container' id='{$field_id}'>" . recaptcha_get_html($publickey, null, $is_ssl, $language) . '</div>'; } } }
/** * Given information provided in an entry, get array of media IDs * * This is necessary because GF doesn't expect to need to update post images, only to create them. * * @see GFFormsModel::create_post() * * @since 1.17 * * @param array $form Gravity Forms form array * @param array $entry Gravity Forms entry array * * @return array Array of "Field ID" => "Media IDs" */ public static function get_post_field_images($form, $entry) { $post_data = self::get_post_fields($form, $entry); $media = get_attached_media('image', $entry['post_id']); $post_images = array(); foreach ($media as $media_item) { foreach ((array) $post_data['images'] as $post_data_item) { if (rgar($post_data_item, 'title') === $media_item->post_title && rgar($post_data_item, 'description') === $media_item->post_content && rgar($post_data_item, 'caption') === $media_item->post_excerpt) { $post_images["{$post_data_item['field_id']}"] = $media_item->ID; } } } return $post_images; }
function gravitiy_extract_value($field, $entry) { $field_id = rgar($field, 'id'); if (!empty($field_id)) { switch ($field['type']) { case 'name': return rgar($entry, "{$field_id}.3") . ' ' . rgar($entry, "{$field_id}.6"); break; default: return rgar($entry, "{$field_id}"); } } return ''; }
function __construct($args = array(), $step = false) { $this->step = $step; if (is_string($args)) { $parts = explode('|', $args); $type = $parts[0]; $id = $parts[1]; } elseif (is_array($args)) { $id = $args['id']; $type = $args['type']; if (isset($args['editable_fields'])) { $this->editable_fields = $args['editable_fields']; } } else { throw new Exception('Assignees must be instantiated with either a string or an array'); } switch ($type) { case 'assignee_field': $entry = $this->step->get_entry(); $assignee_key = rgar($entry, $id); list($this->type, $this->id) = rgexplode('|', $assignee_key, 2); break; case 'assignee_user_field': $entry = $this->step->get_entry(); $this->id = absint(rgar($entry, $id)); $this->type = 'user_id'; break; case 'assignee_role_field': $entry = $this->step->get_entry(); $this->id = sanitize_text_field(rgar($entry, $id)); $this->type = 'role'; break; case 'email_field': $entry = $this->step->get_entry(); $this->id = sanitize_email(rgar($entry, $id)); $this->type = 'email'; break; case 'entry': $entry = $this->step->get_entry(); $this->id = rgar($entry, $id); $this->type = 'user_id'; break; default: $this->type = $type; $this->id = $id; } $this->key = $this->type . '|' . $this->id; }
public function load_form_data($lead, $form_id = '') { $form_id = is_numeric($form_id) ? $form_id : (isset($lead['form_id']) ? $lead['form_id'] : $lead['id']); // No form id if (!$form_id) { return false; } $form = \GFAPI::get_form($form_id); // Invalid form ID if (!$form) { return false; } $file_fields = array(); $url_field = array(); $values = array(); foreach ($form['fields'] as $field) { if (isset($field["inputs"]) && is_array($field['inputs'])) { foreach ($field['inputs'] as $input) { // Extract best label $key = $input['label'] ? $input['label'] : \GFCommon::get_label($field, (string) $input["id"]); // Redundant formatting $key = strtolower(str_replace(array(' '), array('_'), $key)); $value = isset($lead[(string) $input['id']]) ? $lead[(string) $input['id']] : ""; $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES); } } elseif (!rgar($field, 'displayOnly')) { // Extract best label $key = isset($field['adminLabel']) && $field['adminLabel'] != "" ? $field['adminLabel'] : ($field['label'] ? $field['label'] : \GFCommon::get_label($field)); // More redundant formatting $key = strtolower(str_replace(array(' '), array('_'), $key)); $value = isset($lead[$field['id']]) ? $lead[$field['id']] : ""; $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES); } } $values['logo'] = $this->logo ? $this->logo : $values['logo']; // An image field being re-assign from post file data try { $this->assign($values); } catch (Exception $e) { $error = $e->getMessage(); } if (!$this->product_id && isset($lead['source_url'])) { // only needed if used in conjunction with woocommerce fulfillment $this->product_id = url_to_postid($lead['source_url']); } return true; }
/** * The Signature Addon only displays the output in the editable form if it thinks it's in the Admin or a form has been submitted * * @since 1.17 * * @param string $field_content Always empty. Returning not-empty overrides the input. * @param GF_Field $field * @param string|array $value If array, it's a field with multiple inputs. If string, single input. * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. * @param int $form_id Form ID * * @return string Empty string forces Gravity Forms to use the $_POST values */ function edit_entry_field_input($field_content = '', $field, $value = '', $lead_id = 0, $form_id = 0) { $context = function_exists('gravityview_get_context') ? gravityview_get_context() : ''; if ('signature' !== $field->type || 'edit' !== $context) { return $field_content; } // We need to fetch a fresh version of the entry, since the saved entry hasn't refreshed in GV yet. $entry = GravityView_View::getInstance()->getCurrentEntry(); $entry = GFAPI::get_entry($entry['id']); $entry_value = rgar($entry, $field->id); $_POST["input_{$field->id}"] = $entry_value; // Used when Edit Entry form *is* submitted $_POST["input_{$form_id}_{$field->id}_signature_filename"] = $entry_value; // Used when Edit Entry form *is not* submitted return ''; // Return empty string to force using $_POST values instead }
function sales_rep_notification($notification, $form, $entry) { if ($notification['name'] == 'Admin Notification') { //get business zip code $zip = rgar($entry, '2.5'); //get sales rep for that territory's email address global $wpdb; $rep_id = $wpdb->get_var("SELECT user_id FROM wp_usermeta where meta_value LIKE ({$zip}) AND meta_key = 'territory'"); $rep_info = get_user_by('id', $rep_id); // toType can be routing or email $notification['toType'] = 'email'; //notify sales rep $notification['to'] = $rep_info->user_email; $notification['message'] = ' A new business has registered in your sales territory. Please review pending registration for approval.' . $notification['message']; } return $notification; }
public function get_field_input($form, $value = '', $entry = null) { if (is_array($value)) { $value = array_values($value); } $form_id = $form['id']; $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $is_admin = $is_entry_detail || $is_form_editor; $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $class_suffix = $is_entry_detail ? '_admin' : ''; $form_sub_label_placement = rgar($form, 'subLabelPlacement'); $field_sub_label_placement = $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'" : ''; $disabled_text = $is_form_editor ? 'disabled="disabled"' : ''; $first_tabindex = $this->get_tabindex(); $last_tabindex = $this->get_tabindex(); $strength_style = !$this->passwordStrengthEnabled ? "style='display:none;'" : ''; $strength_indicator_label = esc_html__('Strength indicator', 'gravityforms'); $strength = $this->passwordStrengthEnabled || $is_admin ? "<div id='{$field_id}_strength_indicator' class='gfield_password_strength' {$strength_style}>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$strength_indicator_label}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type='hidden' class='gform_hidden' id='{$field_id}_strength' name='input_{$id}_strength' />" : ''; $action = !$is_admin ? "gformShowPasswordStrength(\"{$field_id}\");" : ''; $onchange = $this->passwordStrengthEnabled ? "onchange='{$action}'" : ''; $onkeyup = $this->passwordStrengthEnabled ? "onkeyup='{$action}'" : ''; $confirmation_value = rgpost('input_' . $id . '_2'); $password_value = is_array($value) ? $value[0] : $value; $password_value = esc_attr($password_value); $confirmation_value = esc_attr($confirmation_value); $enter_password_field_input = GFFormsModel::get_input($this, $this->id . ''); $confirm_password_field_input = GFFormsModel::get_input($this, $this->id . '.2'); $enter_password_label = rgar($enter_password_field_input, 'customLabel') != '' ? $enter_password_field_input['customLabel'] : esc_html__('Enter Password', 'gravityforms'); $enter_password_label = gf_apply_filters(array('gform_password', $form_id), $enter_password_label, $form_id); $confirm_password_label = rgar($confirm_password_field_input, 'customLabel') != '' ? $confirm_password_field_input['customLabel'] : esc_html__('Confirm Password', 'gravityforms'); $confirm_password_label = gf_apply_filters(array('gform_password_confirm', $form_id), $confirm_password_label, $form_id); $required_attribute = $this->isRequired ? 'aria-required="true"' : ''; $invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"'; $enter_password_placeholder_attribute = GFCommon::get_input_placeholder_attribute($enter_password_field_input); $confirm_password_placeholder_attribute = GFCommon::get_input_placeholder_attribute($confirm_password_field_input); if ($is_sub_label_above) { return "<div class='ginput_complex{$class_suffix} ginput_container ginput_container_password' id='{$field_id}_container'>\n\t\t\t\t\t<span id='{$field_id}_1_container' class='ginput_left'>\n\t\t\t\t\t\t<label for='{$field_id}' {$sub_label_class_attribute}>{$enter_password_label}</label>\n\t\t\t\t\t\t<input type='password' name='input_{$id}' id='{$field_id}' {$onkeyup} {$onchange} value='{$password_value}' {$first_tabindex} {$enter_password_placeholder_attribute} {$required_attribute} {$invalid_attribute} {$disabled_text}/>\n\t\t\t\t\t</span>\n\t\t\t\t\t<span id='{$field_id}_2_container' class='ginput_right'>\n\t\t\t\t\t\t<label for='{$field_id}_2' {$sub_label_class_attribute}>{$confirm_password_label}</label>\n\t\t\t\t\t\t<input type='password' name='input_{$id}_2' id='{$field_id}_2' {$onkeyup} {$onchange} value='{$confirmation_value}' {$last_tabindex} {$confirm_password_placeholder_attribute} {$required_attribute} {$invalid_attribute} {$disabled_text}/>\n\t\t\t\t\t</span>\n\t\t\t\t\t<div class='gf_clear gf_clear_complex'></div>\n\t\t\t\t</div>{$strength}"; } else { return "<div class='ginput_complex{$class_suffix} ginput_container ginput_container_password' id='{$field_id}_container'>\n\t\t\t\t\t<span id='{$field_id}_1_container' class='ginput_left'>\n\t\t\t\t\t\t<input type='password' name='input_{$id}' id='{$field_id}' {$onkeyup} {$onchange} value='{$password_value}' {$first_tabindex} {$enter_password_placeholder_attribute} {$required_attribute} {$invalid_attribute} {$disabled_text}/>\n\t\t\t\t\t\t<label for='{$field_id}' {$sub_label_class_attribute}>{$enter_password_label}</label>\n\t\t\t\t\t</span>\n\t\t\t\t\t<span id='{$field_id}_2_container' class='ginput_right'>\n\t\t\t\t\t\t<input type='password' name='input_{$id}_2' id='{$field_id}_2' {$onkeyup} {$onchange} value='{$confirmation_value}' {$last_tabindex} {$confirm_password_placeholder_attribute} {$required_attribute} {$invalid_attribute} {$disabled_text}/>\n\t\t\t\t\t\t<label for='{$field_id}_2' {$sub_label_class_attribute}>{$confirm_password_label}</label>\n\t\t\t\t\t</span>\n\t\t\t\t\t<div class='gf_clear gf_clear_complex'></div>\n\t\t\t\t</div>{$strength}"; } }
function get_entries_steps($entry_id) { $capability = apply_filters('gravityflow_web_api_capability_get_entries_steps', 'gravityflow_create_steps'); $this->authorize($capability); $entry = GFAPI::get_entry($entry_id); $form_id = absint($entry['form_id']); $api = new Gravity_Flow_API($form_id); $form_steps = $api->get_steps(); $current_step = $api->get_current_step($entry); $current_step_id = $current_step->get_id(); $response = array(); foreach ($form_steps as $form_step) { $step = $api->get_step($form_step->get_id(), $entry); $is_current_step = $current_step_id == $step->get_id(); $response[] = array('id' => $step->get_id(), 'type' => $step->get_type(), 'label' => $step->get_label(), 'name' => $step->get_name(), 'is_current_step' => $is_current_step, 'is_active' => $step->is_active(), 'supports_expiration' => $step->supports_expiration(), 'assignees' => $this->get_assignees_array($step), 'settings' => $step->get_feed_meta(), 'status' => $is_current_step ? $step->evaluate_status() : rgar($entry, 'workflow_step_status_' . $step->get_id()), 'expiration_timestamp' => $step->get_expiration_timestamp(), 'is_expired' => $step->is_expired(), 'is_queued' => $step->is_queued(), 'entry_count' => $step->entry_count()); } $this->end(200, $response); }