public static function get_form($form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 1) { //looking up form id by form name if (!is_numeric($form_id)) { $form_id = RGFormsModel::get_form_id($form_id); } //reading form metadata $form = RGFormsModel::get_form_meta($form_id, true); $form = RGFormsModel::add_default_properties($form); //disable ajax if form has a reCAPTCHA field (not supported). if ($ajax && self::has_recaptcha_field($form)) { $ajax = false; } $is_postback = false; $is_valid = true; $confirmation_message = ""; $page_number = 1; //If form was submitted, read variables set during form submission procedure $submission_info = isset(self::$submission[$form_id]) ? self::$submission[$form_id] : false; if ($submission_info) { $is_postback = true; $is_valid = rgar($submission_info, "is_valid") || rgar($submission_info, "is_confirmation"); $form = $submission_info["form"]; $lead = $submission_info["lead"]; $confirmation_message = rgget("confirmation_message", $submission_info); if ($is_valid && !RGForms::get("is_confirmation", $submission_info)) { if ($submission_info["page_number"] == 0) { //post submission hook do_action("gform_post_submission", $lead, $form); do_action("gform_post_submission_{$form["id"]}", $lead, $form); } else { //change page hook do_action("gform_post_paging", $form, $submission_info["source_page_number"], $submission_info["page_number"]); do_action("gform_post_paging_{$form["id"]}", $form, $submission_info["source_page_number"], $submission_info["page_number"]); } } } else { if (!current_user_can("administrator")) { RGFormsModel::insert_form_view($form_id, $_SERVER['REMOTE_ADDR']); } } if (rgar($form, "enableHoneypot")) { $form["fields"][] = self::get_honeypot_field($form); } //Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end $form = apply_filters("gform_pre_render_{$form_id}", apply_filters("gform_pre_render", $form, $ajax), $ajax); if ($form == null) { return "<p>" . __("Oops! We could not locate your form.", "gravityforms") . "</p>"; } $has_pages = self::has_pages($form); //calling tab index filter GFCommon::$tab_index = apply_filters("gform_tabindex_{$form_id}", apply_filters("gform_tabindex", $tabindex, $form), $form); //Don't display inactive forms if (!$force_display && !$is_postback) { $form_info = RGFormsModel::get_form($form_id); if (!$form_info->is_active) { return ""; } // If form requires login, check if user is logged in if (rgar($form, "requireLogin")) { if (!is_user_logged_in()) { return empty($form["requireLoginMessage"]) ? "<p>" . __("Sorry. You must be logged in to view this form.", "gravityforms") . "</p>" : "<p>" . GFCommon::gform_do_shortcode($form["requireLoginMessage"]) . "</p>"; } } } // show the form regardless of the following validations when force display is set to true if (!$force_display) { $form_schedule_validation = self::validate_form_schedule($form); // if form schedule validation fails AND this is not a postback, display the validation error // if form schedule validation fails AND this is a postback, make sure is not a valid submission (enables display of confirmation message) if ($form_schedule_validation && !$is_postback || $form_schedule_validation && $is_postback && !$is_valid) { return $form_schedule_validation; } $entry_limit_validation = self::validate_entry_limit($form); // refer to form schedule condition notes above if ($entry_limit_validation && !$is_postback || $entry_limit_validation && $is_postback && !$is_valid) { return $entry_limit_validation; } } $form_string = ""; //When called via a template, this will enqueue the proper scripts //When called via a shortcode, this will be ignored (too late to enqueue), but the scripts will be enqueued via the enqueue_scripts event self::enqueue_form_scripts($form, $ajax); if (empty($confirmation_message)) { $wrapper_css_class = GFCommon::get_browser_class() . " gform_wrapper"; if (!$is_valid) { $wrapper_css_class .= " gform_validation_error"; } //Hidding entire form if conditional logic is on to prevent "hidden" fields from blinking. Form will be set to visible in the conditional_logic.php after the rules have been applied. $style = self::has_conditional_logic($form) ? "style='display:none'" : ""; $custom_wrapper_css_class = !empty($form["cssClass"]) ? " {$form["cssClass"]}_wrapper" : ""; $form_string .= "\n <div class='{$wrapper_css_class}{$custom_wrapper_css_class}' id='gform_wrapper_{$form_id}' " . $style . ">"; $action = add_query_arg(array()); $default_anchor = $has_pages || $ajax ? true : false; $use_anchor = apply_filters("gform_confirmation_anchor_{$form["id"]}", apply_filters("gform_confirmation_anchor", $default_anchor)); if ($use_anchor !== false) { $form_string .= "<a id='gf_{$form_id}' name='gf_{$form_id}' class='gform_anchor' ></a>"; $action .= "#gf_{$form_id}"; } $target = $ajax ? "target='gform_ajax_frame_{$form_id}'" : ""; $form_css_class = !empty($form["cssClass"]) ? "class='{$form["cssClass"]}'" : ""; $action = esc_attr($action); $form_string .= apply_filters("gform_form_tag_{$form_id}", apply_filters("gform_form_tag", "<form method='post' enctype='multipart/form-data' {$target} id='gform_{$form_id}' {$form_css_class} action='{$action}'>", $form), $form); if ($display_title || $display_description) { $form_string .= "\n <div class='gform_heading'>"; if ($display_title) { $form_string .= "\n <h3 class='gform_title'>" . $form['title'] . "</h3>"; } if ($display_description) { $form_string .= "\n <span class='gform_description'>" . rgar($form, 'description') . "</span>"; } $form_string .= "\n </div>"; } $current_page = self::get_current_page($form_id); if ($has_pages && !IS_ADMIN) { $page_count = self::get_max_page_number($form); if ($form["pagination"]["type"] == "percentage") { $form_string .= self::get_progress_bar($form, $form_id, $confirmation_message); } else { if ($form["pagination"]["type"] == "steps") { $form_string .= "\n <div id='gf_page_steps_{$form_id}' class='gf_page_steps'>"; for ($i = 0, $count = sizeof($form["pagination"]["pages"]); $i < $count; $i++) { $step_number = $i + 1; $active_class = $step_number == $current_page ? " gf_step_active" : ""; $first_class = $i == 0 ? " gf_step_first" : ""; $last_class = $i + 1 == $count ? " gf_step_last" : ""; $complete_class = $step_number < $current_page ? " gf_step_completed" : ""; $previous_class = $step_number + 1 == $current_page ? " gf_step_previous" : ""; $next_class = $step_number - 1 == $current_page ? " gf_step_next" : ""; $pending_class = $step_number > $current_page ? " gf_step_pending" : ""; $classes = "gf_step" . $active_class . $first_class . $last_class . $complete_class . $previous_class . $next_class . $pending_class; $classes = GFCommon::trim_all($classes); $form_string .= "\n <div id='gf_step_{$form_id}_{$step_number}' class='{$classes}'><span class='gf_step_number'>{$step_number}</span> {$form["pagination"]["pages"][$i]}</div>"; } $form_string .= "\n <div class='gf_step_clear'></div>\n </div>"; } } } if ($is_postback && !$is_valid) { $validation_message = "<div class='validation_error'>" . __("There was a problem with your submission.", "gravityforms") . " " . __("Errors have been highlighted below.", "gravityforms") . "</div>"; $form_string .= apply_filters("gform_validation_message_{$form["id"]}", apply_filters("gform_validation_message", $validation_message, $form), $form); } $form_string .= "\n <div class='gform_body'>"; //add first page if this form has any page fields if ($has_pages) { $style = self::is_page_active($form_id, 1) ? "" : "style='display:none;'"; $class = !empty($form["firstPageCssClass"]) ? " {$form["firstPageCssClass"]}" : ""; $form_string .= "<div id='gform_page_{$form_id}_1' class='gform_page{$class}' {$style}>\n <div class='gform_page_fields'>"; } $description_class = rgar($form, "descriptionPlacement") == "above" ? "description_above" : "description_below"; $form_string .= "\n <ul id='gform_fields_{$form_id}' class='gform_fields {$form['labelPlacement']} {$description_class}'>"; if (is_array($form['fields'])) { foreach ($form['fields'] as $field) { $field["conditionalLogicFields"] = self::get_conditional_logic_fields($form, $field["id"]); $form_string .= self::get_field($field, RGFormsModel::get_field_value($field, $field_values), false, $form, $field_values); } } $form_string .= "\n </ul>"; if ($has_pages) { $previous_button = self::get_form_button($form["id"], "gform_previous_button_{$form["id"]}", $form["lastPageButton"], __("Previous", "gravityforms"), "button gform_previous_button", __("Previous Page", "gravityforms"), self::get_current_page($form_id) - 1); $form_string .= "</div>" . self::gform_footer($form, "gform_page_footer " . $form['labelPlacement'], $ajax, $field_values, $previous_button, $display_title, $display_description, $is_postback) . "\n </div>"; //closes gform_page } $form_string .= "</div>"; //closes gform_body //suppress form footer for multi-page forms (footer will be included on the last page if (!$has_pages) { $form_string .= self::gform_footer($form, "gform_footer " . $form['labelPlacement'], $ajax, $field_values, "", $display_title, $display_description, $is_postback); } $form_string .= "\n </form>\n </div>"; if ($ajax && $is_postback) { global $wp_scripts; $form_string = "<!DOCTYPE html><html><head>" . "<meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $form_string . "</body></html>"; } if ($ajax && !$is_postback) { $spinner_url = apply_filters("gform_ajax_spinner_url_{$form_id}", apply_filters("gform_ajax_spinner_url", GFCommon::get_base_url() . "/images/spinner.gif", $form), $form); $scroll_position = array('default' => '', 'confirmation' => ''); if ($use_anchor !== false) { $scroll_position['default'] = is_numeric($use_anchor) ? "jQuery(document).scrollTop(" . intval($use_anchor) . ");" : "jQuery(document).scrollTop(jQuery('#gform_wrapper_{$form_id}').offset().top);"; $scroll_position['confirmation'] = is_numeric($use_anchor) ? "jQuery(document).scrollTop(" . intval($use_anchor) . ");" : "jQuery(document).scrollTop(jQuery('#gforms_confirmation_message').offset().top);"; } $form_string .= "\n <iframe style='display:none;width:0px; height:0px;' src='about:blank' name='gform_ajax_frame_{$form_id}' id='gform_ajax_frame_{$form_id}'></iframe>\n <script type='text/javascript'>" . apply_filters("gform_cdata_open", "") . "" . "function gformInitSpinner_{$form_id}(){" . "jQuery('#gform_{$form_id}').submit(function(){" . "if(jQuery('#gform_ajax_spinner_{$form_id}').length == 0){" . "jQuery('#gform_submit_button_{$form_id}, #gform_wrapper_{$form_id} .gform_previous_button, #gform_wrapper_{$form_id} .gform_next_button, #gform_wrapper_{$form_id} .gform_image_button').attr('disabled', true); " . "jQuery('#gform_submit_button_{$form_id}, #gform_wrapper_{$form_id} .gform_next_button, #gform_wrapper_{$form_id} .gform_image_button').after('<' + 'img id=\"gform_ajax_spinner_{$form_id}\" class=\"gform_ajax_spinner\" src=\"{$spinner_url}\" alt=\"\" />'); " . "}" . "} );" . "}" . "jQuery(document).ready(function(\$){" . "gformInitSpinner_{$form_id}();" . "jQuery('#gform_ajax_frame_{$form_id}').load( function(){" . "var contents = jQuery(this).contents().find('*').html();" . "var is_postback = contents.indexOf('GF_AJAX_POSTBACK') >= 0;" . "if(!is_postback){return;}" . "var form_content = jQuery(this).contents().find('#gform_wrapper_{$form_id}');" . "var is_redirect = contents.indexOf('gformRedirect(){') >= 0;" . "jQuery('#gform_submit_button_{$form_id}').removeAttr('disabled');" . "var is_form = !(form_content.length <= 0 || is_redirect);" . "if(is_form){" . "jQuery('#gform_wrapper_{$form_id}').html(form_content.html());" . "{$scroll_position['default']}" . "if(window['gformInitDatepicker']) {gformInitDatepicker();}" . "if(window['gformInitPriceFields']) {gformInitPriceFields();}" . "var current_page = jQuery('#gform_source_page_number_{$form_id}').val();" . "gformInitSpinner_{$form_id}();" . "jQuery(document).trigger('gform_page_loaded', [{$form_id}, current_page]);" . "}" . "else if(!is_redirect){" . "var confirmation_content = jQuery(this).contents().find('#gforms_confirmation_message').html();" . "if(!confirmation_content){" . "confirmation_content = contents;" . "}" . "setTimeout(function(){" . "jQuery('#gform_wrapper_{$form_id}').replaceWith('<' + 'div id=\\'gforms_confirmation_message\\' class=\\'gform_confirmation_message_{$form_id}\\'' + '>' + confirmation_content + '<' + '/div' + '>');" . "{$scroll_position['confirmation']}" . "jQuery(document).trigger('gform_confirmation_loaded', [{$form_id}]);" . "}, 50);" . "}" . "else{" . "jQuery('#gform_{$form_id}').append(contents);" . "if(window['gformRedirect']) {gformRedirect();}" . "}" . "jQuery(document).trigger('gform_post_render', [{$form_id}, current_page]);" . "} );" . "} );" . apply_filters("gform_cdata_close", "") . "</script>"; } $is_first_load = !$is_postback; if (!$ajax || $is_first_load) { self::register_form_init_scripts($form, $field_values); if (apply_filters("gform_init_scripts_footer", false)) { add_action("wp_footer", create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'), 20); add_action("gform_preview_footer", create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');')); } else { $form_string .= self::get_form_init_scripts($form); $form_string .= "<script type='text/javascript'>" . apply_filters("gform_cdata_open", "") . " jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [{$form_id}, {$current_page}]) } ); " . apply_filters("gform_cdata_close", "") . "</script>"; } } return apply_filters('gform_get_form_filter', $form_string); } else { $progress_confirmation = ""; //check admin setting for whether the progress bar should start at zero $start_at_zero = rgars($form, "pagination/display_progressbar_on_confirmation"); //check for filter $start_at_zero = apply_filters("gform_progressbar_start_at_zero", $start_at_zero, $form); //show progress bar on confirmation if ($start_at_zero && $has_pages && !IS_ADMIN && ($form["confirmation"]["type"] == "message" && $form["pagination"]["type"] == "percentage") && $form["pagination"]["display_progressbar_on_confirmation"]) { $progress_confirmation = self::get_progress_bar($form, $form_id, $confirmation_message); if ($ajax) { $progress_confirmation = "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $progress_confirmation . $confirmation_message . "</body></html>"; } else { $progress_confirmation = $progress_confirmation . $confirmation_message; } } else { //return regular confirmation message if ($ajax) { $progress_confirmation = "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $confirmation_message . "</body></html>"; } else { $progress_confirmation = $confirmation_message; } } return $progress_confirmation; } }
public static function get_form($form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 1) { /** * Provides the ability to modify the options used to display the form * * @param array An array of Form Arguments when adding it to a page/post (Like the ID, Title, AJAX or not, etc) */ $form_args = apply_filters('gform_form_args', compact('form_id', 'display_title', 'display_description', 'force_display', 'field_values', 'ajax', 'tabindex')); extract($form_args); //looking up form id by form name if (!is_numeric($form_id)) { $form_id = RGFormsModel::get_form_id($form_id); } //reading form metadata $form = GFAPI::get_form($form_id); $form = self::maybe_add_review_page($form); $action = remove_query_arg('gf_token'); //disable ajax if form has a reCAPTCHA field (not supported). if ($ajax && self::has_recaptcha_field($form)) { $ajax = false; } if (isset($_POST['gform_send_resume_link'])) { $save_email_confirmation = self::handle_save_email_confirmation($form, $ajax); if (is_wp_error($save_email_confirmation)) { // Failed email validation $resume_token = rgpost('gform_resume_token'); $resume_token = sanitize_key($resume_token); $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values($resume_token); if ($incomplete_submission_info['form_id'] == $form_id) { $submission_details_json = $incomplete_submission_info['submission']; $submission_details = json_decode($submission_details_json, true); $partial_entry = $submission_details['partial_entry']; $form = self::update_confirmation($form, $partial_entry, 'form_saved'); $confirmation_message = rgar($form['confirmation'], 'message'); $nl2br = rgar($form['confirmation'], 'disableAutoformat') ? false : true; $confirmation_message = GFCommon::replace_variables($confirmation_message, $form, $partial_entry, false, true, $nl2br); return self::handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax); } } else { return $save_email_confirmation; } } $is_postback = false; $is_valid = true; $confirmation_message = ''; //If form was submitted, read variables set during form submission procedure $submission_info = isset(self::$submission[$form_id]) ? self::$submission[$form_id] : false; if (rgar($submission_info, 'saved_for_later') == true) { $resume_token = $submission_info['resume_token']; $confirmation_message = rgar($submission_info, 'confirmation_message'); return self::handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax); } $partial_entry = $submitted_values = false; if (isset($_GET['gf_token'])) { $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values($_GET['gf_token']); if ($incomplete_submission_info['form_id'] == $form_id) { $submission_details_json = $incomplete_submission_info['submission']; $submission_details = json_decode($submission_details_json, true); $partial_entry = $submission_details['partial_entry']; $submitted_values = $submission_details['submitted_values']; $field_values = $submission_details['field_values']; GFFormsModel::$unique_ids[$form_id] = $submission_details['gform_unique_id']; GFFormsModel::$uploaded_files[$form_id] = $submission_details['files']; self::set_submission_if_null($form_id, 'resuming_incomplete_submission', true); self::set_submission_if_null($form_id, 'form_id', $form_id); $max_page_number = self::get_max_page_number($form); $page_number = $submission_details['page_number'] > $max_page_number ? $max_page_number : $submission_details['page_number']; self::set_submission_if_null($form_id, 'page_number', $page_number); } } if (!is_array($partial_entry)) { /** * A filter that allows disabling of the form view counter * * @param int $form_id The Form ID to filter when disabling the form view counter * @param bool Default set to false (view counter enabled), can be set to true to disable the counter */ $view_counter_disabled = gf_apply_filters(array('gform_disable_view_counter', $form_id), false); if ($submission_info) { $is_postback = true; $is_valid = rgar($submission_info, 'is_valid') || rgar($submission_info, 'is_confirmation'); $form = $submission_info['form']; $lead = $submission_info['lead']; $confirmation_message = rgget('confirmation_message', $submission_info); if ($is_valid && !RGForms::get('is_confirmation', $submission_info)) { if ($submission_info['page_number'] == 0) { /** * Fired after form submission * * @param array $lead The Entry object * @param array $form The Form object */ gf_do_action(array('gform_post_submission', $form['id']), $lead, $form); } else { /** * Fired after the page changes on a multi-page form * * @param array $form The Form object * @param int $submission_info['source_page_number'] The page that was submitted * @param int $submission_info['page_number'] The page that the user is being sent to */ gf_do_action(array('gform_post_paging', $form['id']), $form, $submission_info['source_page_number'], $submission_info['page_number']); } } } elseif (!current_user_can('administrator') && !$view_counter_disabled) { RGFormsModel::insert_form_view($form_id, $_SERVER['REMOTE_ADDR']); } } if (rgar($form, 'enableHoneypot')) { $form['fields'][] = self::get_honeypot_field($form); } //Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end $form = gf_apply_filters(array('gform_pre_render', $form_id), $form, $ajax, $field_values); if ($form == null) { return '<p>' . esc_html__('Oops! We could not locate your form.', 'gravityforms') . '</p>'; } $has_pages = self::has_pages($form); //calling tab index filter GFCommon::$tab_index = gf_apply_filters(array('gform_tabindex', $form_id), $tabindex, $form); //Don't display inactive forms if (!$force_display && !$is_postback) { $form_info = RGFormsModel::get_form($form_id); if (empty($form_info) || !$form_info->is_active) { return ''; } // If form requires login, check if user is logged in if (rgar($form, 'requireLogin')) { if (!is_user_logged_in()) { return empty($form['requireLoginMessage']) ? '<p>' . esc_html__('Sorry. You must be logged in to view this form.', 'gravityforms') . '</p>' : '<p>' . GFCommon::gform_do_shortcode($form['requireLoginMessage']) . '</p>'; } } } // show the form regardless of the following validations when force display is set to true if (!$force_display || $is_postback) { $form_schedule_validation = self::validate_form_schedule($form); // if form schedule validation fails AND this is not a postback, display the validation error // if form schedule validation fails AND this is a postback, make sure is not a valid submission (enables display of confirmation message) if ($form_schedule_validation && !$is_postback || $form_schedule_validation && $is_postback && !$is_valid) { return $form_schedule_validation; } $entry_limit_validation = self::validate_entry_limit($form); // refer to form schedule condition notes above if ($entry_limit_validation && !$is_postback || $entry_limit_validation && $is_postback && !$is_valid) { return $entry_limit_validation; } } $form_string = ''; //When called via a template, this will enqueue the proper scripts //When called via a shortcode, this will be ignored (too late to enqueue), but the scripts will be enqueued via the enqueue_scripts event self::enqueue_form_scripts($form, $ajax); $is_form_editor = GFCommon::is_form_editor(); $is_entry_detail = GFCommon::is_entry_detail(); $is_admin = $is_form_editor || $is_entry_detail; if (empty($confirmation_message)) { $wrapper_css_class = GFCommon::get_browser_class() . ' gform_wrapper'; if (!$is_valid) { $wrapper_css_class .= ' gform_validation_error'; } $form_css_class = esc_attr(rgar($form, 'cssClass')); //Hiding entire form if conditional logic is on to prevent 'hidden' fields from blinking. Form will be set to visible in the conditional_logic.php after the rules have been applied. $style = self::has_conditional_logic($form) ? "style='display:none'" : ''; $custom_wrapper_css_class = !empty($form_css_class) ? " {$form_css_class}_wrapper" : ''; $form_string .= "\n <div class='{$wrapper_css_class}{$custom_wrapper_css_class}' id='gform_wrapper_{$form_id}' " . $style . '>'; $default_anchor = $has_pages || $ajax ? true : false; $use_anchor = gf_apply_filters(array('gform_confirmation_anchor', $form_id), $default_anchor); if ($use_anchor !== false) { $form_string .= "<a id='gf_{$form_id}' class='gform_anchor' ></a>"; $action .= "#gf_{$form_id}"; } $target = $ajax ? "target='gform_ajax_frame_{$form_id}'" : ''; $form_css_class = !empty($form['cssClass']) ? "class='{$form_css_class}'" : ''; $action = esc_url($action); $form_string .= gf_apply_filters(array('gform_form_tag', $form_id), "<form method='post' enctype='multipart/form-data' {$target} id='gform_{$form_id}' {$form_css_class} action='{$action}'>", $form); if ($display_title || $display_description) { $form_string .= "\n <div class='gform_heading'>"; if ($display_title) { $form_string .= "\n <h3 class='gform_title'>" . $form['title'] . '</h3>'; } if ($display_description) { $form_string .= "\n <span class='gform_description'>" . rgar($form, 'description') . '</span>'; } $form_string .= ' </div>'; } $current_page = self::get_current_page($form_id); if ($has_pages && !$is_admin) { if ($form['pagination']['type'] == 'percentage') { $form_string .= self::get_progress_bar($form, $form_id, $confirmation_message); } else { if ($form['pagination']['type'] == 'steps') { $form_string .= "\n <div id='gf_page_steps_{$form_id}' class='gf_page_steps'>"; $pages = isset($form['pagination']['pages']) ? $form['pagination']['pages'] : array(); for ($i = 0, $count = sizeof($pages); $i < $count; $i++) { $step_number = $i + 1; $active_class = $step_number == $current_page ? ' gf_step_active' : ''; $first_class = $i == 0 ? ' gf_step_first' : ''; $last_class = $i + 1 == $count ? ' gf_step_last' : ''; $complete_class = $step_number < $current_page ? ' gf_step_completed' : ''; $previous_class = $step_number + 1 == $current_page ? ' gf_step_previous' : ''; $next_class = $step_number - 1 == $current_page ? ' gf_step_next' : ''; $pending_class = $step_number > $current_page ? ' gf_step_pending' : ''; $classes = 'gf_step' . $active_class . $first_class . $last_class . $complete_class . $previous_class . $next_class . $pending_class; $classes = GFCommon::trim_all($classes); $form_string .= "\n <div id='gf_step_{$form_id}_{$step_number}' class='{$classes}'><span class='gf_step_number'>{$step_number}</span> <span class='gf_step_label'>{$pages[$i]}</span></div>"; } $form_string .= "\n <div class='gf_step_clear'></div>\n </div>"; } } } if ($is_postback && !$is_valid) { $validation_message = "<div class='validation_error'>" . esc_html__('There was a problem with your submission.', 'gravityforms') . ' ' . esc_html__('Errors have been highlighted below.', 'gravityforms') . '</div>'; $form_string .= gf_apply_filters(array('gform_validation_message', $form_id), $validation_message, $form); } $form_string .= "\n <div class='gform_body'>"; //add first page if this form has any page fields if ($has_pages) { $style = self::is_page_active($form_id, 1) ? '' : "style='display:none;'"; $class = !empty($form['firstPageCssClass']) ? " {$form['firstPageCssClass']}" : ''; $class = esc_attr($class); $form_string .= "<div id='gform_page_{$form_id}_1' class='gform_page{$class}' {$style}>\n <div class='gform_page_fields'>"; } $description_class = rgar($form, 'descriptionPlacement') == 'above' ? 'description_above' : 'description_below'; $sublabel_class = rgar($form, 'subLabelPlacement') == 'above' ? 'form_sublabel_above' : 'form_sublabel_below'; $form_string .= "<ul id='gform_fields_{$form_id}' class='" . GFCommon::get_ul_classes($form) . "'>"; if (is_array($form['fields'])) { foreach ($form['fields'] as $field) { /* @var GF_Field $field */ $field->conditionalLogicFields = self::get_conditional_logic_fields($form, $field->id); if (is_array($submitted_values)) { $field_value = rgar($submitted_values, $field->id); } else { $field_value = GFFormsModel::get_field_value($field, $field_values); } $form_string .= self::get_field($field, $field_value, false, $form, $field_values); } } $form_string .= ' </ul>'; if ($has_pages) { $previous_button_alt = rgempty('imageAlt', $form['lastPageButton']) ? __('Previous Page', 'gravityforms') : $form['lastPageButton']['imageAlt']; $previous_button = self::get_form_button($form['id'], "gform_previous_button_{$form['id']}", $form['lastPageButton'], __('Previous', 'gravityforms'), 'gform_previous_button', $previous_button_alt, self::get_current_page($form_id) - 1); /** * Filter through the form previous button when paged * * @param int $form_id The Form ID to filter through * @param string $previous_button The HTML rendered button (rendered with the form ID and the function get_form_button) * @param array $form The Form object to filter through */ $previous_button = gf_apply_filters(array('gform_previous_button', $form_id), $previous_button, $form); $form_string .= '</div>' . self::gform_footer($form, 'gform_page_footer ' . $form['labelPlacement'], $ajax, $field_values, $previous_button, $display_title, $display_description, $is_postback) . ' </div>'; //closes gform_page } $form_string .= '</div>'; //closes gform_body //suppress form footer for multi-page forms (footer will be included on the last page if (!$has_pages) { $form_string .= self::gform_footer($form, 'gform_footer ' . $form['labelPlacement'], $ajax, $field_values, '', $display_title, $display_description, $tabindex); } $form_string .= ' </form> </div>'; if ($ajax && $is_postback) { global $wp_scripts; $form_string = apply_filters('gform_ajax_iframe_content', '<!DOCTYPE html><html><head>' . "<meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $form_string . '</body></html>'); } if ($ajax && !$is_postback) { $spinner_url = gf_apply_filters(array('gform_ajax_spinner_url', $form_id), GFCommon::get_base_url() . '/images/spinner.gif', $form); $scroll_position = array('default' => '', 'confirmation' => ''); if ($use_anchor !== false) { $scroll_position['default'] = is_numeric($use_anchor) ? 'jQuery(document).scrollTop(' . intval($use_anchor) . ');' : "jQuery(document).scrollTop(jQuery('#gform_wrapper_{$form_id}').offset().top);"; $scroll_position['confirmation'] = is_numeric($use_anchor) ? 'jQuery(document).scrollTop(' . intval($use_anchor) . ');' : "jQuery(document).scrollTop(jQuery('#gforms_confirmation_message_{$form_id}').offset().top);"; } $iframe_style = defined('GF_DEBUG') && GF_DEBUG ? 'display:block;width:600px;height:300px;border:1px solid #eee;' : 'display:none;width:0px;height:0px;'; $is_html5 = RGFormsModel::is_html5_enabled(); $iframe_title = $is_html5 ? " title='Ajax Frame'" : ''; $form_string .= "\n <iframe style='{$iframe_style}' src='about:blank' name='gform_ajax_frame_{$form_id}' id='gform_ajax_frame_{$form_id}'" . $iframe_title . "></iframe>\n <script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . '' . 'jQuery(document).ready(function($){' . "gformInitSpinner( {$form_id}, '{$spinner_url}' );" . "jQuery('#gform_ajax_frame_{$form_id}').load( function(){" . "var contents = jQuery(this).contents().find('*').html();" . "var is_postback = contents.indexOf('GF_AJAX_POSTBACK') >= 0;" . 'if(!is_postback){return;}' . "var form_content = jQuery(this).contents().find('#gform_wrapper_{$form_id}');" . "var is_confirmation = jQuery(this).contents().find('#gform_confirmation_wrapper_{$form_id}').length > 0;" . "var is_redirect = contents.indexOf('gformRedirect(){') >= 0;" . 'var is_form = form_content.length > 0 && ! is_redirect && ! is_confirmation;' . 'if(is_form){' . "jQuery('#gform_wrapper_{$form_id}').html(form_content.html());" . "setTimeout( function() { /* delay the scroll by 50 milliseconds to fix a bug in chrome */ {$scroll_position['default']} }, 50 );" . "if(window['gformInitDatepicker']) {gformInitDatepicker();}" . "if(window['gformInitPriceFields']) {gformInitPriceFields();}" . "var current_page = jQuery('#gform_source_page_number_{$form_id}').val();" . "gformInitSpinner( {$form_id}, '{$spinner_url}' );" . "jQuery(document).trigger('gform_page_loaded', [{$form_id}, current_page]);" . "window['gf_submitting_{$form_id}'] = false;" . '}' . 'else if(!is_redirect){' . "var confirmation_content = jQuery(this).contents().find('#gforms_confirmation_message_{$form_id}').html();" . 'if(!confirmation_content){' . 'confirmation_content = contents;' . '}' . 'setTimeout(function(){' . "jQuery('#gform_wrapper_{$form_id}').replaceWith('<' + 'div id=\\'gforms_confirmation_message_{$form_id}\\' class=\\'gform_confirmation_message_{$form_id} gforms_confirmation_message\\'' + '>' + confirmation_content + '<' + '/div' + '>');" . "{$scroll_position['confirmation']}" . "jQuery(document).trigger('gform_confirmation_loaded', [{$form_id}]);" . "window['gf_submitting_{$form_id}'] = false;" . '}, 50);' . '}' . 'else{' . "jQuery('#gform_{$form_id}').append(contents);" . "if(window['gformRedirect']) {gformRedirect();}" . '}' . "jQuery(document).trigger('gform_post_render', [{$form_id}, current_page]);" . '} );' . '} );' . apply_filters('gform_cdata_close', '') . '</script>'; } $is_first_load = !$is_postback; if (!$ajax || $is_first_load) { self::register_form_init_scripts($form, $field_values, $ajax); if (apply_filters('gform_init_scripts_footer', false)) { add_action('wp_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'), 20); add_action('gform_preview_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');')); } else { $form_string .= self::get_form_init_scripts($form); $form_string .= "<script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . " jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [{$form_id}, {$current_page}]) } ); " . apply_filters('gform_cdata_close', '') . '</script>'; } } return gf_apply_filters(array('gform_get_form_filter', $form_id), $form_string, $form); } else { $progress_confirmation = ''; //check admin setting for whether the progress bar should start at zero $start_at_zero = rgars($form, 'pagination/display_progressbar_on_confirmation'); $start_at_zero = apply_filters('gform_progressbar_start_at_zero', $start_at_zero, $form); //show progress bar on confirmation if ($start_at_zero && $has_pages && !$is_admin && ($form['confirmation']['type'] == 'message' && $form['pagination']['type'] == 'percentage')) { $progress_confirmation = self::get_progress_bar($form, $form_id, $confirmation_message); if ($ajax) { $progress_confirmation = apply_filters('gform_ajax_iframe_content', "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $progress_confirmation . '</body></html>'); } } else { //return regular confirmation message if ($ajax) { $progress_confirmation = apply_filters('gform_ajax_iframe_content', "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $confirmation_message . '</body></html>'); } else { $progress_confirmation = $confirmation_message; } } return $progress_confirmation; } }
public static function get_form($form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 1) { // echo "$form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 1 "; /** * @To do tomorrow * datact if its approved or not => done * Lacking will find the correct container and hide it. * /app/wwwroot/wp-content/plugins/gravityforms/includes/fields/class-gf-field-creditcard.php * /app/wwwroot/wp-content/themes/TPO10/functions.php * /app/wwwroot/wp-content/plugins/gravityforms/form_display */ /** * STEPS * * Find way how to filter if approved or not => done * Find the actual html of the credit cards fields */ // gform_lead_id = 1137 // [gform_edit_id] => 1137 // [input_id] => 1137 // [input_payment_status] => approved //EDIT // gform_edit_id = 1137 // input_id = 1137 // [input_form_id] => 75 // [input_payment_status] => approved // [gform_submit] => 75 //IF CLICK NEXT /** * [gform_lead_id] => 1137 * GET DATA BY THAT ID CHECK IF APPROVED OR NOT APPROVED */ //IF EDIT /** * [input_payment_status] => approved * [input_id] => 1137 * [gform_edit_id] => 1137 * [input_form_id] => 75 */ // print_r($_POST); // echo "total post " . count($_POST) . '<br>'; // if (count($_POST) > 1) { // // $form_id_lead = $_POST['gform_edit_id']; // $form_id = $_POST['input_form_id']; // if (empty($form_id_lead)) { // $form_id_lead = $_POST['gform_lead_id']; // } // if (empty($form_id)) { // $form_id = $_POST['gform_submit']; // } // // $paymentStatus = ''; // $isApproved = false; // if (!empty($form_id) and !empty($form_id_lead)) { // // echo "form id is not empty <br>"; // global $wpdb; // $results = $wpdb->get_results("SELECT * FROM wp_rg_lead WHERE form_id = $form_id AND id = $form_id_lead", 'ARRAY_A'); // // // echo "<pre>"; // // echo "result from db"; // // print_r($results); // // // // echo "result from post"; // // print_r($_POST); // // // // echo "</pre>"; // // echo "This is the form printed <br> form id " . $form_id; // // provides the ability to modify the options used to display the form // // // // if ($_POST['input_payment_status'] == 'approved' || $_POST['input_payment_status'] == 'approve' || $_POST['input_payment_status'] == 'Approved') { // //echo "approved<br>"; // //add code to hide credit card // $isApproved = true; // $paymentStatus = $_POST['input_payment_status']; // // } // if ($results[0]['payment_status'] == 'approved' || $results[0]['payment_status'] == 'approve' || $results[0]['payment_status'] == 'Approved') { // //echo "approved<br>"; // //add code to hide credit card // $isApproved = true; // $paymentStatus = $results[0]['payment_status']; // } else { // //do nothing // // echo "not approved<br>"; // } // // // echo "form id " . $form_id . '<br>'; // // echo "lead id " . $form_id_lead . '<br>'; // // echo "status " . $results[0]['payment_status'] . '<br>'; // // // echo "db status = " . $results[0][0]['payment_status'] . '<br>'; // // echo "form id " . $form_id . '<br>'; // // cho "lead id " . $form_id_lead . '<br>'; // // } else { // // echo "form id is empty <br>"; // } // end if // } //end if form /** * Get the value for the wp_users.user_status * and set the if user type is member or none member * if member then hide credit card if not then show credit card */ // global $current_user; // if($current_user->user_status == 0) { // $userType = 'none member'; // } else { // $userType = 'member'; // } /** * Another option above but prefer for above code because it's short * Set it to true when when you want to use it. * same function to above code. */ if (false) { global $wpdb; $user_ID = get_current_user_id(); $userInfo = $wpdb->get_results("SELECT * FROM wp_users WHERE ID = " . $user_ID, 'ARRAY_A'); if ($userInfo[0]['user_status'] == 0) { $userType = 'none member'; } else { $userType = 'member'; } } // $currentUserInfo = get_currentuserinfo(); //echo "<pre>"; // print_r($userInfo); //print_r($currentUserInfo); //echo "id " . $current_user->user_status; //echo "</pre>"; //echo "user status " . $current_user->user_status; // exit; /** * Original code from this plugin */ $form_args = apply_filters('gform_form_args', compact('form_id', 'display_title', 'display_description', 'force_display', 'field_values', 'ajax', 'tabindex')); extract($form_args); //looking up form id by form name if (!is_numeric($form_id)) { $form_id = RGFormsModel::get_form_id($form_id); } //reading form metadata //check code line $form = RGFormsModel::get_form_meta($form_id, true); // echo "<pre>"; // print_r($form); //echo "<pre>"; // echo 'title ' . $form['title'] . '<br>'; // echo 'desc ' . $form['description'] . '<br>'; // echo 'fields <br>'; // print( $form['fields'] ); // $fields_array = (array) $form['fields']; // echo "<pre>"; // print_r($fields_array); // echo "</pre>"; // echo "feld " . $fields_array[0]->type . '<br>'; // exit; $action = remove_query_arg('gf_token'); //disable ajax if form has a reCAPTCHA field (not supported). if ($ajax && self::has_recaptcha_field($form)) { $ajax = false; } if (isset($_POST['gform_send_resume_link'])) { $save_email_confirmation = self::handle_save_email_confirmation($form, $ajax); if (is_wp_error($save_email_confirmation)) { // Failed email validation $resume_token = rgpost('gform_resume_token'); $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values(rgpost('gform_resume_token')); if ($incomplete_submission_info['form_id'] == $form_id) { $submission_details_json = $incomplete_submission_info['submission']; $submission_details = json_decode($submission_details_json, true); $partial_entry = $submission_details['partial_entry']; $form = self::update_confirmation($form, $partial_entry, 'form_saved'); $confirmation_message = rgar($form['confirmation'], 'message'); $nl2br = rgar($form['confirmation'], 'disableAutoformat') ? false : true; $confirmation_message = GFCommon::replace_variables($confirmation_message, $form, $partial_entry, false, true, $nl2br); return self::handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax); } } else { return $save_email_confirmation; } } $is_postback = false; $is_valid = true; $confirmation_message = ''; //If form was submitted, read variables set during form submission procedure $submission_info = isset(self::$submission[$form_id]) ? self::$submission[$form_id] : false; if (rgar($submission_info, 'saved_for_later') == true) { $resume_token = $submission_info['resume_token']; $confirmation_message = rgar($submission_info, 'confirmation_message'); return self::handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax); } $partial_entry = $submitted_values = false; if (isset($_GET['gf_token'])) { $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values($_GET['gf_token']); if ($incomplete_submission_info['form_id'] == $form_id) { $submission_details_json = $incomplete_submission_info['submission']; $submission_details = json_decode($submission_details_json, true); $partial_entry = $submission_details['partial_entry']; $submitted_values = $submission_details['submitted_values']; $field_values = $submission_details['field_values']; GFFormsModel::$unique_ids[$form_id] = $submission_details['gform_unique_id']; GFFormsModel::$uploaded_files[$form_id] = $submission_details['files']; self::set_submission_if_null($form_id, 'resuming_incomplete_submission', true); self::set_submission_if_null($form_id, 'form_id', $form_id); self::set_submission_if_null($form_id, 'page_number', $submission_details['page_number']); } } if (!is_array($partial_entry)) { $view_counter_disabled = gf_apply_filters('gform_disable_view_counter', $form_id, false); if ($submission_info) { $is_postback = true; $is_valid = rgar($submission_info, 'is_valid') || rgar($submission_info, 'is_confirmation'); $form = $submission_info['form']; $lead = $submission_info['lead']; $confirmation_message = rgget('confirmation_message', $submission_info); if ($is_valid && !RGForms::get('is_confirmation', $submission_info)) { if ($submission_info['page_number'] == 0) { //post submission hook gf_do_action('gform_post_submission', $form['id'], $lead, $form); } else { //change page hook gf_do_action('gform_post_paging', $form['id'], $form, $submission_info['source_page_number'], $submission_info['page_number']); } } } elseif (!current_user_can('administrator') && !$view_counter_disabled) { RGFormsModel::insert_form_view($form_id, $_SERVER['REMOTE_ADDR']); } } if (rgar($form, 'enableHoneypot')) { $form['fields'][] = self::get_honeypot_field($form); } // print test // echo " submition id " . $form['id'] . '<br>'; //Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end //check this part $form = gf_apply_filters('gform_pre_render', $form_id, $form, $ajax, $field_values); // echo "<pre>"; // // print_r($form); // // echo "<pre>"; if ($form == null) { return '<p>' . esc_html__('Oops! We could not locate your form.', 'gravityforms') . '</p>'; } $has_pages = self::has_pages($form); //calling tab index filter GFCommon::$tab_index = gf_apply_filters('gform_tabindex', $form_id, $tabindex, $form); //Don't display inactive forms if (!$force_display && !$is_postback) { //check here.. $form_info = RGFormsModel::get_form($form_id); if (empty($form_info) || !$form_info->is_active) { return ''; } // If form requires login, check if user is logged in if (rgar($form, 'requireLogin')) { if (!is_user_logged_in()) { return empty($form['requireLoginMessage']) ? '<p>' . esc_html__('Sorry. You must be logged in to view this form.', 'gravityforms') . '</p>' : '<p>' . GFCommon::gform_do_shortcode($form['requireLoginMessage']) . '</p>'; } } } // show the form regardless of the following validations when force display is set to true if (!$force_display || $is_postback) { $form_schedule_validation = self::validate_form_schedule($form); // if form schedule validation fails AND this is not a postback, display the validation error // if form schedule validation fails AND this is a postback, make sure is not a valid submission (enables display of confirmation message) if ($form_schedule_validation && !$is_postback || $form_schedule_validation && $is_postback && !$is_valid) { return $form_schedule_validation; } $entry_limit_validation = self::validate_entry_limit($form); // refer to form schedule condition notes above if ($entry_limit_validation && !$is_postback || $entry_limit_validation && $is_postback && !$is_valid) { return $entry_limit_validation; } } $form_string = ''; //When called via a template, this will enqueue the proper scripts //When called via a shortcode, this will be ignored (too late to enqueue), but the scripts will be enqueued via the enqueue_scripts event self::enqueue_form_scripts($form, $ajax); $is_form_editor = GFCommon::is_form_editor(); $is_entry_detail = GFCommon::is_entry_detail(); $is_admin = $is_form_editor || $is_entry_detail; if (empty($confirmation_message)) { $wrapper_css_class = GFCommon::get_browser_class() . ' gform_wrapper'; if (!$is_valid) { $wrapper_css_class .= ' gform_validation_error'; } //Hiding entire form if conditional logic is on to prevent 'hidden' fields from blinking. Form will be set to visible in the conditional_logic.php after the rules have been applied. $style = self::has_conditional_logic($form) ? "style='display:none'" : ''; $custom_wrapper_css_class = !empty($form['cssClass']) ? " {$form['cssClass']}_wrapper" : ''; $form_string .= "\n <div class='{$wrapper_css_class}{$custom_wrapper_css_class}' id='gform_wrapper_{$form_id}' " . $style . '>'; $default_anchor = $has_pages || $ajax ? true : false; $use_anchor = gf_apply_filters('gform_confirmation_anchor', $form_id, $default_anchor); if ($use_anchor !== false) { $form_string .= "<a id='gf_{$form_id}' name='gf_{$form_id}' class='gform_anchor' ></a>"; $action .= "#gf_{$form_id}"; } $target = $ajax ? "target='gform_ajax_frame_{$form_id}'" : ''; $form_css_class = !empty($form['cssClass']) ? "class='{$form['cssClass']}'" : ''; $action = esc_url($action); $form_string .= gf_apply_filters('gform_form_tag', $form_id, "<form method='post' enctype='multipart/form-data' {$target} id='gform_{$form_id}' {$form_css_class} action='{$action}'>", $form); if ($display_title || $display_description) { $form_string .= "\n <div class='gform_heading'>"; if ($display_title) { $form_string .= "\n <h3 class='gform_title'>" . $form['title'] . '</h3>'; } if ($display_description) { $form_string .= "\n <span class='gform_description'>" . rgar($form, 'description') . '</span>'; } $form_string .= ' </div>'; } $current_page = self::get_current_page($form_id); if ($has_pages && !$is_admin) { if ($form['pagination']['type'] == 'percentage') { $form_string .= self::get_progress_bar($form, $form_id, $confirmation_message); } else { if ($form['pagination']['type'] == 'steps') { $form_string .= "\n <div id='gf_page_steps_{$form_id}' class='gf_page_steps'>"; $pages = isset($form['pagination']['pages']) ? $form['pagination']['pages'] : array(); for ($i = 0, $count = sizeof($pages); $i < $count; $i++) { $step_number = $i + 1; $active_class = $step_number == $current_page ? ' gf_step_active' : ''; $first_class = $i == 0 ? ' gf_step_first' : ''; $last_class = $i + 1 == $count ? ' gf_step_last' : ''; $complete_class = $step_number < $current_page ? ' gf_step_completed' : ''; $previous_class = $step_number + 1 == $current_page ? ' gf_step_previous' : ''; $next_class = $step_number - 1 == $current_page ? ' gf_step_next' : ''; $pending_class = $step_number > $current_page ? ' gf_step_pending' : ''; $classes = 'gf_step' . $active_class . $first_class . $last_class . $complete_class . $previous_class . $next_class . $pending_class; $classes = GFCommon::trim_all($classes); $form_string .= "\n <div id='gf_step_{$form_id}_{$step_number}' class='{$classes}'><span class='gf_step_number'>{$step_number}</span> <span class='gf_step_label'>{$pages[$i]}</span></div>"; } $form_string .= "\n <div class='gf_step_clear'></div>\n </div>"; } } } if ($is_postback && !$is_valid) { $validation_message = "<div class='validation_error'>" . esc_html__('There was a problem with your submission.', 'gravityforms') . ' ' . esc_html__('Errors have been highlighted below.', 'gravityforms') . '</div>'; $form_string .= gf_apply_filters('gform_validation_message', $form_id, $validation_message, $form); } $form_string .= "\n <div class='gform_body'>"; //add first page if this form has any page fields if ($has_pages) { $style = self::is_page_active($form_id, 1) ? '' : "style='display:none;'"; $class = !empty($form['firstPageCssClass']) ? " {$form['firstPageCssClass']}" : ''; $form_string .= "<div id='gform_page_{$form_id}_1' class='gform_page{$class}' {$style}>\n <div class='gform_page_fields'>"; } $description_class = rgar($form, 'descriptionPlacement') == 'above' ? 'description_above' : 'description_below'; $sublabel_class = rgar($form, 'subLabelPlacement') == 'above' ? 'form_sublabel_above' : 'form_sublabel_below'; $form_string .= "<ul id='gform_fields_{$form_id}' class='" . GFCommon::get_ul_classes($form) . "'>"; /** * Here the field is being filtered * So if detect credit card then no credit card will show. * * Documentation: * * 1.) DB: * - tpocom_dash.wp_rg_lead.payment_status = "approved" or NULL * * 2.) Form.Hidden Field: * - Field Label: "payment status" * - Parameter Name: "payment_status_value" * * 3.) Form.Credit Card: * - Advance * - Enable condition logic "Hide" this field "all" of the following match "payment status" is "approved" */ /** * @var $paymentStatus - will hold the variable if approved or not approved. * It is declared first line of this function, you can see the condition there. * * @var $field->inputName - set to "payment_status_value" <- this is the parameter name. * that's the string we set the setting up the form in the GUI at admin area. */ /** * @var userType = member or none member */ // $userType = 'member'; // $paymentStatus = 'approved'; // $userType = 'member'; // get membership type // get payment status $paymentStatus = self::getPaymentStatus($form); $memberShipStatus = self::getMembershipStatus(); $fieldValue = self::filterPaymentAndMemberShip($paymentStatus, $memberShipStatus); // echo "payment status $paymentStatus membership status $memberShipStatus field value = $fieldValue <br>"; if (is_array($form['fields'])) { $counter = 0; foreach ($form['fields'] as $field) { /** * Hide through form condition */ if ($field->inputName == 'member_type_value') { $form_string .= self::get_field($field, $fieldValue, false, $form, $field_values); } else { $field->conditionalLogicFields = self::get_conditional_logic_fields($form, $field->id); if (is_array($submitted_values)) { $field_value = $submitted_values[$field->id]; } else { $field_value = GFFormsModel::get_field_value($field, $field_values); } $form_string .= self::get_field($field, $field_value, false, $form, $field_values); } } } $form_string .= ' </ul>'; if ($has_pages) { $previous_button = self::get_form_button($form['id'], "gform_previous_button_{$form['id']}", $form['lastPageButton'], __('Previous', 'gravityforms'), 'gform_previous_button', __('Previous Page', 'gravityforms'), self::get_current_page($form_id) - 1); $previous_button = gf_apply_filters('gform_previous_button', $form_id, $previous_button, $form); $form_string .= '</div>' . self::gform_footer($form, 'gform_page_footer ' . $form['labelPlacement'], $ajax, $field_values, $previous_button, $display_title, $display_description, $is_postback) . ' </div>'; //closes gform_page } $form_string .= '</div>'; //closes gform_body //suppress form footer for multi-page forms (footer will be included on the last page if (!$has_pages) { $form_string .= self::gform_footer($form, 'gform_footer ' . $form['labelPlacement'], $ajax, $field_values, '', $display_title, $display_description, $tabindex); } // echo "submition id 1 " . $form['id'] . '<br>'; $form_string .= ' </form> </div>'; if ($ajax && $is_postback) { global $wp_scripts; $form_string = apply_filters('gform_ajax_iframe_content', '<!DOCTYPE html><html><head>' . "<meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $form_string . '</body></html>'); } if ($ajax && !$is_postback) { $spinner_url = gf_apply_filters('gform_ajax_spinner_url', $form_id, GFCommon::get_base_url() . '/images/spinner.gif', $form); $scroll_position = array('default' => '', 'confirmation' => ''); if ($use_anchor !== false) { $scroll_position['default'] = is_numeric($use_anchor) ? 'jQuery(document).scrollTop(' . intval($use_anchor) . ');' : "jQuery(document).scrollTop(jQuery('#gform_wrapper_{$form_id}').offset().top);"; $scroll_position['confirmation'] = is_numeric($use_anchor) ? 'jQuery(document).scrollTop(' . intval($use_anchor) . ');' : "jQuery(document).scrollTop(jQuery('#gforms_confirmation_message_{$form_id}').offset().top);"; } $iframe_style = defined('GF_DEBUG') && GF_DEBUG ? 'display:block;width:600px;height:300px;border:1px solid #eee;' : 'display:none;width:0px;height:0px;'; $is_html5 = RGFormsModel::is_html5_enabled(); $iframe_title = $is_html5 ? " title='Ajax Frame'" : ''; $form_string .= "\n <iframe style='{$iframe_style}' src='about:blank' name='gform_ajax_frame_{$form_id}' id='gform_ajax_frame_{$form_id}'" . $iframe_title . "></iframe>\n <script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . '' . 'jQuery(document).ready(function($){' . "gformInitSpinner( {$form_id}, '{$spinner_url}' );" . "jQuery('#gform_ajax_frame_{$form_id}').load( function(){" . "var contents = jQuery(this).contents().find('*').html();" . "var is_postback = contents.indexOf('GF_AJAX_POSTBACK') >= 0;" . 'if(!is_postback){return;}' . "var form_content = jQuery(this).contents().find('#gform_wrapper_{$form_id}');" . "var is_confirmation = jQuery(this).contents().find('#gform_confirmation_wrapper_{$form_id}').length > 0;" . "var is_redirect = contents.indexOf('gformRedirect(){') >= 0;" . 'var is_form = form_content.length > 0 && ! is_redirect && ! is_confirmation;' . 'if(is_form){' . "jQuery('#gform_wrapper_{$form_id}').html(form_content.html());" . "setTimeout( function() { /* delay the scroll by 50 milliseconds to fix a bug in chrome */ {$scroll_position['default']} }, 50 );" . "if(window['gformInitDatepicker']) {gformInitDatepicker();}" . "if(window['gformInitPriceFields']) {gformInitPriceFields();}" . "var current_page = jQuery('#gform_source_page_number_{$form_id}').val();" . "gformInitSpinner( {$form_id}, '{$spinner_url}' );" . "jQuery(document).trigger('gform_page_loaded', [{$form_id}, current_page]);" . "window['gf_submitting_{$form_id}'] = false;" . '}' . 'else if(!is_redirect){' . "var confirmation_content = jQuery(this).contents().find('#gforms_confirmation_message_{$form_id}').html();" . 'if(!confirmation_content){' . 'confirmation_content = contents;' . '}' . 'setTimeout(function(){' . "jQuery('#gform_wrapper_{$form_id}').replaceWith('<' + 'div id=\\'gforms_confirmation_message_{$form_id}\\' class=\\'gform_confirmation_message_{$form_id} gforms_confirmation_message\\'' + '>' + confirmation_content + '<' + '/div' + '>');" . "{$scroll_position['confirmation']}" . "jQuery(document).trigger('gform_confirmation_loaded', [{$form_id}]);" . "window['gf_submitting_{$form_id}'] = false;" . '}, 50);' . '}' . 'else{' . "jQuery('#gform_{$form_id}').append(contents);" . "if(window['gformRedirect']) {gformRedirect();}" . '}' . "jQuery(document).trigger('gform_post_render', [{$form_id}, current_page]);" . '} );' . '} );' . apply_filters('gform_cdata_close', '') . '</script>'; } $is_first_load = !$is_postback; if (!$ajax || $is_first_load) { self::register_form_init_scripts($form, $field_values, $ajax); if (apply_filters('gform_init_scripts_footer', false)) { add_action('wp_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'), 20); add_action('gform_preview_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');')); } else { $form_string .= self::get_form_init_scripts($form); $form_string .= "<script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . " jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [{$form_id}, {$current_page}]) } ); " . apply_filters('gform_cdata_close', '') . '</script>'; } } return gf_apply_filters('gform_get_form_filter', $form_id, $form_string, $form); } else { $progress_confirmation = ''; //check admin setting for whether the progress bar should start at zero $start_at_zero = rgars($form, 'pagination/display_progressbar_on_confirmation'); $start_at_zero = apply_filters('gform_progressbar_start_at_zero', $start_at_zero, $form); //show progress bar on confirmation if ($start_at_zero && $has_pages && !$is_admin && ($form['confirmation']['type'] == 'message' && $form['pagination']['type'] == 'percentage')) { $progress_confirmation = self::get_progress_bar($form, $form_id, $confirmation_message); if ($ajax) { $progress_confirmation = apply_filters('gform_ajax_iframe_content', "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $progress_confirmation . '</body></html>'); } } else { //return regular confirmation message if ($ajax) { $progress_confirmation = apply_filters('gform_ajax_iframe_content', "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $confirmation_message . '</body></html>'); } else { $progress_confirmation = $confirmation_message; } } return $progress_confirmation; } }
public static function get_form($form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 1) { //looking up form id by form name if (!is_numeric($form_id)) { $form_id = RGFormsModel::get_form_id($form_id); } //reading form metadata $form = RGFormsModel::get_form_meta($form_id, true); $form = RGFormsModel::add_default_properties($form); //disable ajax if form has a reCAPTCHA field (not supported). if ($ajax && self::has_recaptcha_field($form)) { $ajax = false; } $is_postback = false; $is_valid = true; $confirmation_message = ""; $page_number = 1; //If form was submitted, read variables set during form submission procedure $submission_info = isset(self::$submission[$form_id]) ? self::$submission[$form_id] : false; if ($submission_info) { $is_postback = true; $is_valid = $submission_info["is_valid"] || rgget("is_confirmation", $submission_info); $form = $submission_info["form"]; $lead = $submission_info["lead"]; $confirmation_message = rgget("confirmation_message", $submission_info); if ($is_valid && !RGForms::get("is_confirmation", $submission_info)) { if ($submission_info["page_number"] == 0) { //post submission hook do_action("gform_post_submission", $lead, $form); do_action("gform_post_submission_{$form["id"]}", $lead, $form); } else { //change page hook do_action("gform_post_paging", $form, $submission_info["source_page_number"], $submission_info["page_number"]); do_action("gform_post_paging_{$form["id"]}", $form, $submission_info["source_page_number"], $submission_info["page_number"]); } } } else { if (!current_user_can("administrator")) { RGFormsModel::insert_form_view($form_id, $_SERVER['REMOTE_ADDR']); } } if (rgar($form, "enableHoneypot")) { $form["fields"][] = self::get_honeypot_field($form); } //Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end $form = apply_filters("gform_pre_render_{$form_id}", apply_filters("gform_pre_render", $form)); if ($form == null) { return "<p>" . __("Oops! We could not locate your form.", "gravityforms") . "</p>"; } $has_pages = self::has_pages($form); //calling tab index filter GFCommon::$tab_index = apply_filters("gform_tabindex_{$form_id}", apply_filters("gform_tabindex", $tabindex, $form), $form); //Don't display inactive forms if (!$force_display && !$is_postback) { $form_info = RGFormsModel::get_form($form_id); if (!$form_info->is_active) { return ""; } //If form has a schedule, make sure it is within the configured start and end dates if (rgar($form, "scheduleForm")) { $local_time_start = sprintf("%s %02d:%02d %s", $form["scheduleStart"], $form["scheduleStartHour"], $form["scheduleStartMinute"], $form["scheduleStartAmpm"]); $local_time_end = sprintf("%s %02d:%02d %s", $form["scheduleEnd"], $form["scheduleEndHour"], $form["scheduleEndMinute"], $form["scheduleEndAmpm"]); $timestamp_start = strtotime($local_time_start . ' +0000'); $timestamp_end = strtotime($local_time_end . ' +0000'); $now = current_time("timestamp"); if (!empty($form["scheduleStart"]) && $now < $timestamp_start || !empty($form["scheduleEnd"]) && $now > $timestamp_end) { return empty($form["scheduleMessage"]) ? "<p>" . __("Sorry. This form is no longer available.", "gravityforms") . "</p>" : "<p>" . GFCommon::gform_do_shortcode($form["scheduleMessage"]) . "</p>"; } } //If form has a limit of entries, check current entry count if (rgar($form, "limitEntries")) { $period = rgar($form, "limitEntriesPeriod"); $range = self::get_limit_period_dates($period); $entry_count = RGFormsModel::get_lead_count($form_id, "", null, null, $range["start_date"], $range["end_date"]); if ($entry_count >= $form["limitEntriesCount"]) { return empty($form["limitEntriesMessage"]) ? "<p>" . __("Sorry. This form is no longer accepting new submissions.", "gravityforms") . "</p>" : "<p>" . GFCommon::gform_do_shortcode($form["limitEntriesMessage"]) . "</p>"; } } // If form requires login, check if user is logged in if (rgar($form, "requireLogin")) { if (!is_user_logged_in()) { return empty($form["requireLoginMessage"]) ? "<p>" . __("Sorry. You must be logged in to view this form.", "gravityforms") . "</p>" : "<p>" . GFCommon::gform_do_shortcode($form["requireLoginMessage"]) . "</p>"; } } } $form_string = ""; //When called via a template, this will enqueue the proper scripts //When called via a shortcode, this will be ignored (too late to enqueue), but the scripts will be enqueued via the enqueue_scripts event self::enqueue_form_scripts($form, $ajax); if (empty($confirmation_message)) { $wrapper_css_class = GFCommon::get_browser_class() . " gform_wrapper"; if (!$is_valid) { $wrapper_css_class .= " gform_validation_error"; } //Hidding entire form if conditional logic is on to prevent "hidden" fields from blinking. Form will be set to visible in the conditional_logic.php after the rules have been applied. $style = self::has_conditional_logic($form) ? "style='display:none'" : ""; $form_string .= "\n <div class='{$wrapper_css_class}' id='gform_wrapper_{$form_id}' " . $style . ">"; $action = add_query_arg(array()); $default_anchor = $has_pages || $ajax ? true : false; $use_anchor = apply_filters("gform_confirmation_anchor_{$form["id"]}", apply_filters("gform_confirmation_anchor", $default_anchor)); if ($use_anchor !== false) { $form_string .= "<a name='gf_{$form_id}' class='gform_anchor' ></a>"; $action .= "#gf_{$form_id}"; } $target = $ajax ? "target='gform_ajax_frame_{$form_id}'" : ""; $form_css_class = !empty($form["cssClass"]) ? "class='{$form["cssClass"]}'" : ""; $action = esc_attr($action); $form_string .= apply_filters("gform_form_tag_{$form_id}", apply_filters("gform_form_tag", "<form method='post' enctype='multipart/form-data' {$target} id='gform_{$form_id}' {$form_css_class} action='{$action}'>", $form), $form); if ($display_title || $display_description) { $form_string .= "\n <div class='gform_heading'>"; if ($display_title) { $form_string .= "\n <h3 class='gform_title'>" . $form['title'] . "</h3>"; } if ($display_description) { $form_string .= "\n <span class='gform_description'>" . rgar($form, 'description') . "</span>"; } $form_string .= "\n </div>"; } if ($has_pages && !IS_ADMIN) { $page_count = self::get_max_page_number($form); $current_page = self::get_current_page($form_id); if ($form["pagination"]["type"] == "percentage") { $percent = floor($current_page / $page_count * 100) . "%"; $page_name = rgar(rgar($form["pagination"], "pages"), $current_page - 1); $page_name = !empty($page_name) ? " - " . $page_name : ""; $style = $form["pagination"]["style"]; $color = $style == "custom" ? " color:{$form["pagination"]["color"]};" : ""; $bgcolor = $style == "custom" ? " background-color:{$form["pagination"]["backgroundColor"]};" : ""; $form_string .= "\n <div id='gf_progressbar_wrapper_{$form_id}' class='gf_progressbar_wrapper'>\n <h3 class='gf_progressbar_title'>" . __("Step", "gravityforms") . " {$current_page} " . __("of", "gravityforms") . " {$page_count}{$page_name}</h3>\n <div class='gf_progressbar'>\n <div class='gf_progressbar_percentage percentbar_{$style}' style='width:{$percent};{$color}{$bgcolor}'><span>{$percent}</span></div>\n </div>\n </div>"; } else { if ($form["pagination"]["type"] == "steps") { $form_string .= "\n <div id='gf_page_steps_{$form_id}' class='gf_page_steps'>"; for ($i = 0, $count = sizeof($form["pagination"]["pages"]); $i < $count; $i++) { $step_number = $i + 1; $active_class = $step_number == $current_page ? " gf_step_active" : ""; $first_class = $i == 0 ? " gf_step_first" : ""; $last_class = $i + 1 == $count ? " gf_step_last" : ""; $complete_class = $step_number < $current_page ? " gf_step_completed" : ""; $previous_class = $step_number + 1 == $current_page ? " gf_step_previous" : ""; $next_class = $step_number - 1 == $current_page ? " gf_step_next" : ""; $pending_class = $step_number > $current_page ? " gf_step_pending" : ""; $classes = "gf_step" . $active_class . $first_class . $last_class . $complete_class . $previous_class . $next_class . $pending_class; $classes = GFCommon::trim_all($classes); $form_string .= "\n <div id='gf_step_{$form_id}_{$step_number}' class='{$classes}'><span class='gf_step_number'>{$step_number}</span> {$form["pagination"]["pages"][$i]}</div>"; } $form_string .= "\n <div class='gf_step_clear'></div>\n </div>"; } } } if ($is_postback && !$is_valid) { $validation_message = "<div class='validation_error'>" . __("There was a problem with your submission.", "gravityforms") . " " . __("Errors have been highlighted below.", "gravityforms") . "</div>"; $form_string .= apply_filters("gform_validation_message_{$form["id"]}", apply_filters("gform_validation_message", $validation_message, $form), $form); } $form_string .= "\n <div class='gform_body'>"; //add first page if this form has any page fields if ($has_pages) { $style = self::is_page_active($form_id, 1) ? "" : "style='display:none;'"; $class = !empty($form["firstPageCssClass"]) ? " {$form["firstPageCssClass"]}" : ""; $form_string .= "<div id='gform_page_{$form_id}_1' class='gform_page{$class}' {$style}>\n <div class='gform_page_fields'>"; } $description_class = rgar($form, "descriptionPlacement") == "above" ? "description_above" : "description_below"; $form_string .= "\n <ul id='gform_fields_{$form_id}' class='gform_fields {$form['labelPlacement']} {$description_class}'>"; if (is_array($form['fields'])) { foreach ($form['fields'] as $field) { $field["conditionalLogicFields"] = self::get_conditional_logic_fields($form, $field["id"]); $form_string .= self::get_field($field, RGFormsModel::get_field_value($field, $field_values), false, $form, $field_values); } } $form_string .= "\n </ul>"; if ($has_pages) { $previous_button = self::get_form_button($form["id"], "gform_previous_button_{$form["id"]}", $form["lastPageButton"], __("Previous", "gravityforms"), "button gform_previous_button", __("Previous Page", "gravityforms"), self::get_current_page($form_id) - 1); $form_string .= "</div>" . self::gform_footer($form, "gform_page_footer " . $form['labelPlacement'], $ajax, $field_values, $previous_button, $display_title, $display_description, $is_postback) . "\n </div>"; //closes gform_page } $form_string .= "</div>"; //closes gform_body //suppress form footer for multi-page forms (footer will be included on the last page if (!$has_pages) { $form_string .= self::gform_footer($form, "gform_footer " . $form['labelPlacement'], $ajax, $field_values, "", $display_title, $display_description, $is_postback); } $form_string .= "\n </form>\n </div>"; //adding conditional logic script if conditional logic is configured for this form. //get_conditional_logic also adds the chosen script for the enhanced dropdown option. //if this form does not have conditional logic, add chosen script separately if (self::has_conditional_logic($form)) { $form_string .= self::get_conditional_logic($form); } else { if (self::has_enhanced_dropdown($form)) { $form_string .= "<script type='text/javascript'>//<![CDATA[\n" . self::get_chosen_init_script($form) . "\n//]]></script>"; } } //adding currency config if there are any product fields in the form if (self::has_price_field($form)) { if (!class_exists("RGCurrency")) { require_once "currency.php"; } $form_string .= "<script type='text/javascript'>//<![CDATA[\n if(window[\"gformInitPriceFields\"]) jQuery(document).ready(function(){gformInitPriceFields();}); window['gf_currency_config'] = " . GFCommon::json_encode(RGCurrency::get_currency(GFCommon::get_currency())) . "; \n//]]></script>"; } if (self::has_password_strength($form)) { $form_string .= "<script type='text/javascript'>//<![CDATA[\nif(!window['gf_text']){window['gf_text'] = new Array();} window['gf_text']['password_blank'] = '" . __("Strength indicator", "gravityforms") . "'; window['gf_text']['password_mismatch'] = '" . __("Mismatch", "gravityforms") . "';window['gf_text']['password_bad'] = '" . __("Bad", "gravityforms") . "'; window['gf_text']['password_short'] = '" . __("Short", "gravityforms") . "'; window['gf_text']['password_good'] = '" . __("Good", "gravityforms") . "'; window['gf_text']['password_strong'] = '" . __("Strong", "gravityforms") . "';\n//]]></script>"; } if (GFCommon::has_credit_card_field($form)) { $card_rules = self::get_credit_card_rules(); $form_string .= "<script type='text/javascript'>//<![CDATA[\n if(!window['gf_cc_rules']){window['gf_cc_rules'] = new Array(); } window['gf_cc_rules'] = " . GFCommon::json_encode($card_rules) . "; \n//]]></script>"; } if ($ajax && $is_postback) { global $wp_scripts; $form_string = "<!DOCTYPE html><html><head>" . "<script type='text/javascript' src='" . $wp_scripts->base_url . $wp_scripts->registered["jquery"]->src . "'></script>" . "<script type='text/javascript' src='" . GFCommon::get_base_url() . "/js/conditional_logic.js'></script>" . "<meta charset='UTF-8' /></head><body>" . $form_string . "</body></html>"; } if ($ajax && !$is_postback) { $spinner_url = apply_filters("gform_ajax_spinner_url_{$form_id}", apply_filters("gform_ajax_spinner_url", GFCommon::get_base_url() . "/images/spinner.gif", $form), $form); $scroll_position = array('default' => '', 'confirmation' => ''); if ($use_anchor !== false) { $scroll_position['default'] = is_numeric($use_anchor) ? "jQuery(document).scrollTop(" . intval($use_anchor) . ");" : "jQuery(document).scrollTop(jQuery('#gform_wrapper_{$form_id}').offset().top);"; $scroll_position['confirmation'] = is_numeric($use_anchor) ? "jQuery(document).scrollTop(" . intval($use_anchor) . ");" : "jQuery(document).scrollTop(jQuery('#gforms_confirmation_message').offset().top);"; } $form_string .= "\n <iframe style='display:none;width:0px; height:0px;' src='about:blank' name='gform_ajax_frame_{$form_id}' id='gform_ajax_frame_{$form_id}'></iframe>\n <script type='text/javascript'>//<![CDATA[\n" . "function gformInitSpinner(){" . "jQuery('#gform_{$form_id}').submit(function(){" . "jQuery('#gform_submit_button_{$form_id}').attr('disabled', true).after('<' + 'img id=\"gform_ajax_spinner_{$form_id}\" class=\"gform_ajax_spinner\" src=\"{$spinner_url}\" alt=\"\" />');" . "jQuery('#gform_wrapper_{$form_id} .gform_previous_button').attr('disabled', true); " . "jQuery('#gform_wrapper_{$form_id} .gform_next_button').attr('disabled', true).after('<' + 'img id=\"gform_ajax_spinner_{$form_id}\" class=\"gform_ajax_spinner\" src=\"{$spinner_url}\" alt=\"\" />');" . "});" . "}" . "jQuery(document).ready(function(\$){" . "gformInitSpinner();" . "jQuery('#gform_ajax_frame_{$form_id}').load( function(){" . "var form_content = jQuery(this).contents().find('#gform_wrapper_{$form_id}');" . "var confirmation_content = jQuery(this).contents().find('#gforms_confirmation_message');" . "jQuery('#gform_submit_button_{$form_id}').removeAttr('disabled');" . "if(form_content.length > 0){" . "jQuery('#gform_wrapper_{$form_id}').html(form_content.html());" . "{$scroll_position['default']}" . "if(window['gformInitDatepicker']) {gformInitDatepicker();}" . "if(window['gformInitPriceFields']) {gformInitPriceFields();}" . "var current_page = jQuery('#gform_source_page_number_{$form_id}').val();" . "gformInitSpinner();" . "jQuery(document).trigger('gform_page_loaded', [{$form_id}, current_page]);" . "}" . "else if(confirmation_content.length > 0){" . "setTimeout(function(){" . "jQuery('#gform_wrapper_{$form_id}').replaceWith('<' + 'div id=\\'gforms_confirmation_message\\' class=\\'gform_confirmation_message_{$form_id}\\'' + '>' + confirmation_content.html() + '<' + '/div' + '>');" . "{$scroll_position['confirmation']}" . "jQuery(document).trigger('gform_confirmation_loaded', [{$form_id}]);" . "}, 50);" . "}" . "else{" . "jQuery('#gform_{$form_id}').append(jQuery(this).contents().find('*').html());" . "if(window['gformRedirect']) gformRedirect();" . "}" . "jQuery(document).trigger('gform_post_render', [{$form_id}, current_page]);" . "});" . "});" . "\n//]]></script>"; } return apply_filters('gform_get_form_filter', $form_string); } else { if ($ajax) { $confirmation_message = "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body>" . $confirmation_message . "</body></html>"; } return $confirmation_message; } }
public static function get_form($form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null) { //reading form metadata $form = RGFormsModel::get_form_meta($form_id); //Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end $form = apply_filters("gform_pre_render_{$form_id}", apply_filters("gform_pre_render", $form)); if ($form == null) { return "<p>" . __("Oops! We could not locate your form.", "gravityforms") . "</p>"; } //Don't display inactive forms if (!$force_display) { $form_info = RGFormsModel::get_form($form_id); if (!$form_info->is_active) { return ""; } //If form has a schedule, make sure it is within the configured start and end dates if ($form["scheduleForm"]) { $local_time_start = sprintf("%s %02d:%02d %s", $form["scheduleStart"], $form["scheduleStartHour"], $form["scheduleStartMinute"], $form["scheduleStartAmpm"]); $local_time_end = sprintf("%s %02d:%02d %s", $form["scheduleEnd"], $form["scheduleEndHour"], $form["scheduleEndMinute"], $form["scheduleEndAmpm"]); $timestamp_start = strtotime($local_time_start . ' +0000'); $timestamp_end = strtotime($local_time_end . ' +0000'); $now = current_time("timestamp"); if (!empty($form["scheduleStart"]) && $now < $timestamp_start || !empty($form["scheduleEnd"]) && $now > $timestamp_end) { return empty($form["scheduleMessage"]) ? "<p>" . __("Sorry. This form is no longer available.", "gravityforms") . "</p>" : "<p>" . $form["scheduleMessage"] . "</p>"; } } //If form has a limit of entries, check current entry count if ($form["limitEntries"]) { $entry_count = RGFormsModel::get_lead_count($form_id, ""); if ($entry_count >= $form["limitEntriesCount"]) { return empty($form["limitEntriesMessage"]) ? "<p>" . __("Sorry. This form is no longer accepting new submissions.", "gravityforms") . "</p>" : "<p>" . $form["limitEntriesMessage"] . "</p>"; } } } $form_string = ""; //When called via a template, this will enqueue the proper scripts //When called via a shortcode, this will be ignored (too late to enqueue), but the scripts will be enqueued via the enqueue_scripts event self::enqueue_form_scripts($form); //handling postback if form was submitted $is_postback = $_POST["is_submit_" . $form_id]; $is_valid = true; if ($is_postback) { $is_valid = self::validate($form, $field_values); if ($is_valid) { //pre submission action do_action("gform_pre_submission", $form); //pre submission filter $form = apply_filters("gform_pre_submission_filter", $form); //handle submission $lead = array(); $confirmation_message = self::handle_submission($form, $lead); //post submission hook do_action("gform_post_submission", $lead, $form); } } else { //recording form view. Ignores views from administrators if (!current_user_can("administrator")) { RGFormsModel::insert_form_view($form_id, $_SERVER['REMOTE_ADDR']); } } if (empty($confirmation_message)) { //Hidding entire form if conditional logic is on to prevent "hidden" fields from blinking. Form will be set to visible in the conditional_logic.php after the rules have been applied. $style = self::has_conditional_logic($form) ? "style='display:none'" : ""; $form_string .= "\n <div class='gform_wrapper' id='gform_wrapper_{$form_id}' " . $style . ">\n <form method='post' enctype='multipart/form-data' id='gform_{$form_id}' class='" . $form["cssClass"] . "' action=''>"; if ($display_title || $display_description) { $form_string .= "\n <div class='gform_heading'>"; if ($display_title) { $form_string .= "\n <h3 class='gform_title'>" . $form['title'] . "</h3>"; } if ($display_description) { $form_string .= "\n <span class='gform_description'>" . $form['description'] . "</span>"; } $form_string .= "\n </div>"; } if ($is_postback && !$is_valid) { $validation_message = "<div class='validation_error'>" . __("There was a problem with your submission.", "gravityforms") . "<br /> " . __("Errors have been highlighted below ", "gravityforms") . "</div>"; $form_string .= apply_filters("gform_validation_message", $validation_message, $form); } $form_string .= "\n <div class='gform_body'>\n <input type='hidden' class='gform_hidden' name='is_submit_{$form_id}' value='1'/>\n <ul id='gform_fields_{$form_id}' class='gform_fields " . $form['labelPlacement'] . "'>"; if (is_array($form['fields'])) { foreach ($form['fields'] as $field) { $field["conditionalLogicFields"] = self::get_conditional_logic_fields($form, $field["id"]); $form_string .= self::get_field($field, RGFormsModel::get_field_value($field, $field_values), false, $form, $field_values); } } $form_string .= "\n </ul>\n </div>\n <div class='gform_footer " . $form['labelPlacement'] . "'>"; $tabindex = GFCommon::$tab_index++; if ($form["button"]["type"] == "text" || empty($form["button"]["imageUrl"])) { $button_text = empty($form["button"]["text"]) ? __("Submit", "gravityforms") : $form["button"]["text"]; $button_input = "<input type='submit' class='button' value='" . esc_attr($button_text) . "' tabindex='{$tabindex}'/>"; } else { $imageUrl = $form["button"]["imageUrl"]; $button_input = "<input type='image' src='{$imageUrl}' tabindex='{$tabindex}'/>"; } $button_input = apply_filters("gform_submit_button", $button_input, $form); $button_input = apply_filters("gform_submit_button_{$form_id}", $button_input, $form); $form_string .= $button_input; if (current_user_can("gform_full_access")) { $form_string .= " <a href='" . get_bloginfo("wpurl") . "/wp-admin/admin.php?page=gf_edit_forms&id=" . $form_id . "'>" . __("Edit this form", "gravityforms") . "</a>"; } $form_string .= "\n </div>\n </form>\n </div>"; if (self::has_conditional_logic($form)) { $form_string .= self::get_conditional_logic($form); } return $form_string; } else { return $confirmation_message; } }