function sticky_pre_populate_the_form($form)
{
    if ($form['isSticky']) {
        $current_page = GFFormDisplay::get_current_page($form["id"]);
        if ($current_page == 1) {
            global $valid;
            // Get the stored entry ID
            $entry_id = sticky_getEntryOptionKeyForGF($form);
            // If the form has been submited, is valid and we are not in the preview area
            if ($valid && strpos($_SERVER['REQUEST_URI'], 'preview') == false) {
                // We have a previously saved entry
                if (get_option($entry_id)) {
                    // Get the entry
                    $form_fields = RGFormsModel::get_lead(get_option($entry_id));
                    // If an entry is found we need prepare if for insertion into the form
                    if ($form_fields && $form_fields["status"] != "trash") {
                        // Create new correctly formated keys and get rid of the old ones
                        foreach ($form_fields as $key => &$value) {
                            // If the key is numeric we need to change it from [X.X] to [input_X_X]
                            if (is_numeric($key)) {
                                $new_key = str_replace(".", "_", "input_{$key}");
                                $form_fields[$new_key] = $form_fields[$key];
                                unset($form_fields[$key]);
                                // If we have an upload field
                                if (strpos($value, "uploads/")) {
                                    $upload = $value;
                                }
                            }
                        }
                        // Add is_submit_id field
                        $form_id = $form['id'];
                        $form_fields["is_submit_{$form_id}"] = "1";
                        $_POST = $form_fields;
                        // If no entry is found; unset the stored entry ID
                    } else {
                        update_option($entry_id, "");
                    }
                }
            }
        }
    }
    // Replace {upload} with reference to uploaded file
    if (isset($upload)) {
        foreach ($form["fields"] as &$field) {
            foreach ($field as $key => &$value) {
                if ($key == "content") {
                    $value = str_replace("{upload}", $upload, $value);
                }
            }
        }
    }
    return $form;
}
 public function render($form, $ajax)
 {
     if (!class_exists('GFFormDisplay') || self::isDisabled()) {
         return $form;
     }
     self::enqueueScripts($form, $ajax);
     self::updateRenderedCount();
     $next = GFFormDisplay::get_max_field_id($form) + 1;
     $template = sprintf($this->template, get_option('rg_gforms_captcha_public_key'));
     $opts = array('type' => 'section', '_is_entry_detail' => NULL, 'id' => $next, 'label' => '', 'adminLabel' => '', 'isRequired' => false, 'size' => 'medium', 'errorMessage' => '', 'inputs' => NULL, 'displayOnly' => true, 'labelPlacement' => '', 'content' => '', 'formId' => $form['id'], 'pageNumber' => GFFormDisplay::get_current_page($form['id']), 'conditionalLogic' => '', 'cssClass' => $this->buCAPTCHAIdentifier . '_section');
     $form['fields'][] = GF_Fields::create($opts);
     $captcha_opts = array('type' => 'html', 'id' => $next + 1, 'content' => apply_filters('bu_gravityforms_global_recaptcha_div', $template), 'cssClass' => $this->buCAPTCHAIdentifier);
     $form['fields'][] = GF_Fields::create(array_merge($opts, $captcha_opts));
     return $form;
 }
 function is_last_page($form)
 {
     $page_number = GFFormDisplay::get_current_page($form['id']);
     $last_page = count($form['pagination']['pages']);
     return $page_number >= $last_page;
 }
    function get_form($options)
    {
        global $woocommerce;
        $product = null;
        if (function_exists('get_product')) {
            $product = get_product($this->product_id);
        } else {
            $product = new WC_Product($this->product_id);
        }
        extract(shortcode_atts(array('display_title' => true, 'display_description' => true, 'display_inactive' => false, 'field_values' => false, 'ajax' => false, 'tabindex' => 1, 'label_subtotal' => __('Subtotal', 'wc_gf_addons'), 'label_options' => __('Options', 'wc_gf_addons'), 'label_total' => __('Total', 'wc_gf_addons'), 'disable_label_subtotal' => 'no', 'disable_label_options' => 'no', 'disable_label_total' => 'no', 'disable_calculations' => 'no'), $options));
        //Get the form meta so we can make sure the form exists.
        $form_meta = RGFormsModel::get_form_meta($this->form_id);
        if (!empty($form_meta)) {
            if (!empty($_POST)) {
                $_POST['gform_submit'] = isset($_POST['gform_old_submit']) ? $_POST['gform_old_submit'] : '';
                $_POST['gform_old_submit'] = $_POST['gform_submit'];
            }
            $form = RGForms::get_form($this->form_id, $display_title, $display_description, $display_inactive, $field_values, $ajax, $tabindex);
            unset($_POST['gform_submit']);
            $form = str_replace('</form>', '', $form);
            $form = str_replace('gform_submit', 'gform_old_submit', $form);
            $this->current_page = GFFormDisplay::get_current_page($this->form_id);
            $this->next_page = $this->current_page + 1;
            $this->previous_page = $this->current_page - 1;
            $this->next_page = $this->next_page > $this->get_max_page_number($form_meta) ? 0 : $this->next_page;
            if ($product->product_type == 'variable' || $product->product_type == 'variable-subscription') {
                echo '<div class="gform_variation_wrapper gform_wrapper single_variation_wrap">';
            } else {
                echo '<div class="gform_variation_wrapper gform_wrapper">';
            }
            if ($product->is_type('variable')) {
                //echo '<input type="hidden" name="add-to-cart" value="variation" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            } elseif ($product->has_child()) {
                //echo '<input type="hidden" name="add-to-cart" value="group" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            } else {
                //echo '<input type="hidden" name="add-to-cart" value="' . $this->product_id . '" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            }
            if (wc_is_21x()) {
                wp_nonce_field('add_to_cart');
            } else {
                $woocommerce->nonce_field('add_to_cart');
            }
            echo '<a id="_form_' . $this->form_id . '" href="#_form_' . $this->form_id . '" class="gform_anchor"></a>';
            echo $form;
            echo '<input type="hidden" name="gform_form_id" id="gform_form_id" value="' . $this->form_id . '" />';
            echo '<input type="hidden" id="woocommerce_get_action" value="" />';
            echo '<input type="hidden" id="woocommerce_product_base_price" value="' . $product->get_price() . '" />';
            $description_class = rgar($form_meta, "descriptionPlacement") == "above" ? "description_above" : "description_below";
            ?>

			<?php 
            $this->on_print_scripts();
            if ($disable_calculations == 'no') {
                ?>

				<div class="product_totals">
					<ul id="gform_totals_<?php 
                echo $this->form_id;
                ?>
" class="gform_fields <?php 
                echo $form_meta['labelPlacement'] . ' ' . $description_class;
                ?>
">
						<li class="gfield" <?php 
                if ($disable_label_subtotal == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
							<label class="gfield_label"><?php 
                echo $label_subtotal;
                ?>
</label>
							<div class="ginput_container">
								<span class="formattedBasePrice ginput_total"></span>
							</div>
						</li>
						<li class="gfield" <?php 
                if ($disable_label_options == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
							<label class="gfield_label"><?php 
                echo $label_options;
                ?>
</label>
							<div class="ginput_container">
								<span class="formattedVariationTotal ginput_total"></span>
							</div>
						</li>
						<li class="gfield" <?php 
                if ($disable_label_total == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
							<label class="gfield_label"><?php 
                echo $label_total;
                ?>
</label>
							<div class="ginput_container">
								<span class="formattedTotalPrice ginput_total"></span>
							</div>
						</li>
					</ul>
				</div>
				<style>
					.single_variation .price {
						display:none !important;
					}
				</style>
			<?php 
            }
            ?>
			<style>
				.hidden-total {
					display:none !important;
				}
			</style>



			<?php 
            echo '</div>';
        }
    }
 public static function add_dynamic_field_value_filter($name, $field, $input_id = false)
 {
     $form = GFAPI::get_form($field['formId']);
     $value = self::preview_replace_variables($name, $form);
     if ($value == $name) {
         return;
     }
     $is_submit = !empty($_POST["is_submit_{$form['id']}"]);
     $current_page = GFFormDisplay::get_current_page($form['id']);
     $field_page = rgar($field, 'pageNumber');
     $input_id_bits = explode('.', $input_id);
     $input_id = array_pop($input_id_bits);
     $key = implode('_', array_filter(array('input', $field['id'], $input_id)));
     $on_field_page = $current_page == $field_page;
     $has_value = !rgempty($key);
     if ($is_submit && $on_field_page) {
         if (!$has_value || self::get_page_progression($form['id']) < $current_page) {
             $_POST[$key] = $value;
         }
     } else {
         $value = str_replace("'", '&#39;', $value);
         add_filter("gform_field_value_{$name}", create_function("", "return '{$value}';"));
     }
 }
Exemplo n.º 6
0
function populate_html($form)
{
    //this is a 2-page form with the data from page one being displayed in an html field on page 2
    $current_page = GFFormDisplay::get_current_page($form['id']);
    $html_content = "The information you have submitted is as follows:<br/><ul>";
    if ($current_page == 2) {
        foreach ($form['fields'] as &$field) {
            if ($field->inputName == 'entry-id') {
                $entry_id = rgpost('input_' . $field->id);
            }
        }
        $fieldIDarr['project-name'] = 151;
        $fieldIDarr['short-project-desc'] = 16;
        $fieldIDarr['exhibit-contain-fire'] = 83;
        $fieldIDarr['interactive-exhibit'] = 84;
        $fieldIDarr['fire-safety-issues'] = 85;
        //find the project name for submitted entry-id
        $entry = GFAPI::get_entry($entry_id);
        foreach ($form['fields'] as &$field) {
            if (isset($fieldIDarr[$field->inputName])) {
                $field->defaultValue = $entry[$fieldIDarr[$field->inputName]];
            }
        }
    }
    return $form;
}