Exemplo n.º 1
0
 public static function maybe_process_form()
 {
     $form_id = isset($_POST["gform_submit"]) ? $_POST["gform_submit"] : 0;
     if ($form_id) {
         require_once GFCommon::get_base_path() . "/form_display.php";
         GFFormDisplay::process_form($form_id);
     }
 }
Exemplo n.º 2
0
 public static function maybe_process_form()
 {
     $form_id = isset($_POST['gform_submit']) ? absint($_POST['gform_submit']) : 0;
     if ($form_id) {
         $form_info = RGFormsModel::get_form($form_id);
         $is_valid_form = $form_info && $form_info->is_active;
         if ($is_valid_form) {
             require_once GFCommon::get_base_path() . '/form_display.php';
             GFFormDisplay::process_form($form_id);
         }
     } elseif (isset($_POST['gform_send_resume_link'])) {
         require_once GFCommon::get_base_path() . '/form_display.php';
         GFFormDisplay::process_send_resume_link();
     }
 }
Exemplo n.º 3
0
 public static function maybe_process_form()
 {
     $form_id = isset($_POST["gform_submit"]) ? $_POST["gform_submit"] : 0;
     if ($form_id) {
         $form_info = RGFormsModel::get_form($form_id);
         $is_valid_form = $form_info && $form_info->is_active;
         if ($is_valid_form) {
             require_once GFCommon::get_base_path() . "/form_display.php";
             GFFormDisplay::process_form($form_id);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Submits a form. Use this function to send input values through the complete form submission process.
  * Supports field validation, notifications, confirmations, multiple-pages and save & continue.
  *
  * Example usage:
  * $input_values['input_1']   = 'Single line text';
  * $input_values['input_2_3'] = 'First name';
  * $input_values['input_2_6'] = 'Last name';
  * $input_values['input_5']   = 'A paragraph of text.';
  * //$input_values['gform_save'] = true; // support for save and continue
  *
  * $result = GFAPI::submit_form( 52, $input_values );
  *
  * Example output for a successful submission:
  * 'is_valid' => boolean true
  * 'page_number' => int 0
  * 'source_page_number' => int 1
  * 'confirmation_message' => string 'confirmation message [snip]'
  *
  * Example output for failed validation:
  * 'is_valid' => boolean false
  * 'validation_messages' =>
  *      array (size=1)
  *          2 => string 'This field is required. Please enter the first and last name.'
  *	'page_number' => int 1
  *  'source_page_number' => int 1
  *	'confirmation_message' => string ''
  *
  *
  * Example output for save and continue:
  * 'is_valid' => boolean true
  * 'page_number' => int 1
  * 'source_page_number' => int 1
  * 'confirmation_message' => string 'Please use the following link to return to your form from any computer. [snip]'
  * 'resume_token' => string '045f941cc4c04d479556bab1db6d3495'
  *
  *
  * @param int $form_id The Form ID
  * @param array $input_values An array of values. Not $_POST, that will be automatically merged with the $input_values.
  * @param array $field_values Optional.
  * @param int $target_page Optional.
  * @param int $source_page Optional.
  *
  * @return array An array containing the result of the submission.
  */
 public static function submit_form($form_id, $input_values, $field_values = array(), $target_page = 0, $source_page = 1)
 {
     $form_id = absint($form_id);
     $form = GFAPI::get_form($form_id);
     if (empty($form) || !$form['is_active'] || $form['is_trash']) {
         return new WP_Error('form_not_found', __('Your form could not be found', 'gravityforms'));
     }
     $input_values['is_submit_' . $form_id] = true;
     $input_values['gform_submit'] = $form_id;
     $input_values['gform_target_page_number_' . $form_id] = absint($target_page);
     $input_values['gform_source_page_number_' . $form_id] = absint($source_page);
     $input_values['gform_field_values'] = $field_values;
     require_once GFCommon::get_base_path() . '/form_display.php';
     if (!isset($_POST)) {
         $_POST = array();
     }
     $_POST = array_merge_recursive($_POST, $input_values);
     try {
         GFFormDisplay::process_form($form_id);
     } catch (Exception $ex) {
         return new WP_Error('error_processing_form', __('There was an error while processing the form:', 'gravityforms') . ' ' . $ex->getCode() . ' ' . $ex->getMessage());
     }
     if (empty(GFFormDisplay::$submission)) {
         return new WP_Error('error_processing_form', __('There was an error while processing the form:', 'gravityforms'));
     }
     $submissions_array = GFFormDisplay::$submission;
     $submission_details = $submissions_array[$form_id];
     $result = array();
     $result['is_valid'] = $submission_details['is_valid'];
     if ($result['is_valid'] == false) {
         $validation_messages = array();
         foreach ($submission_details['form']['fields'] as $field) {
             if ($field->failed_validation) {
                 $validation_messages[$field->id] = $field->validation_message;
             }
         }
         $result['validation_messages'] = $validation_messages;
     }
     $result['page_number'] = $submission_details['page_number'];
     $result['source_page_number'] = $submission_details['source_page_number'];
     $result['confirmation_message'] = $submission_details['confirmation_message'];
     if (isset($submission_details['resume_token'])) {
         $result['resume_token'] = $submission_details['resume_token'];
         $form = self::get_form($form_id);
         $result['confirmation_message'] = GFFormDisplay::replace_save_variables($result['confirmation_message'], $form, $result['resume_token']);
     }
     return $result;
 }
 public function maybe_save_confirmation()
 {
     /* On paged forms all processing is suppressed, so we still need to do something */
     $form_id = isset($_POST['gform_submit']) ? $_POST['gform_submit'] : 0;
     if (!$form_id) {
         return;
     }
     if (!isset($_POST['gform_save_state_' . $form_id])) {
         return;
     }
     $form_info = RGFormsModel::get_form($form_id);
     $is_valid_form = $form_info && $form_info->is_active;
     if (!$is_valid_form) {
         return;
     }
     $form = RGFormsModel::get_form_meta($form_id);
     if (!isset($form['requireLogin']) || !isset($form['enableFormState'])) {
         return;
     }
     if (!$form['requireLogin'] || !$form['enableFormState']) {
         return;
     }
     if (!GFCommon::has_pages($form)) {
         return;
     }
     /* Spoof the page number and make-believe */
     $_POST["gform_target_page_number_{$form_id}"] = 65535;
     require_once GFCommon::get_base_path() . '/form_display.php';
     GFFormDisplay::process_form($form_id);
 }
 function add_cart_item_data($cart_item_meta, $product_id)
 {
     global $woocommerce;
     if (isset($cart_item_meta['_gravity_form_data']) && isset($cart_item_meta['_gravity_form_lead'])) {
         return $cart_item_meta;
     }
     $gravity_form_data = get_post_meta($product_id, '_gravity_form_data', true);
     $cart_item_meta['_gravity_form_data'] = $gravity_form_data;
     if ($gravity_form_data && is_array($gravity_form_data) && isset($gravity_form_data['id']) && intval($gravity_form_data['id']) > 0) {
         $form_id = $gravity_form_data['id'];
         $form_meta = RGFormsModel::get_form_meta($form_id);
         //Gravity forms generates errors and warnings.  To prevent these from conflicting with other things, we are going to disable warnings and errors.
         $err_level = error_reporting();
         error_reporting(0);
         //MUST disable notifications manually.
         add_filter('gform_disable_user_notification_' . $form_id, array(&$this, 'disable_notifications'), 10, 3);
         add_filter('gform_disable_admin_notification_' . $form_id, array(&$this, 'disable_notifications'), 10, 3);
         add_filter('gform_disable_notification_' . $form_id, array(&$this, 'disable_notifications'), 10, 3);
         add_filter("gform_confirmation_" . $form_id, array($this, "disable_confirmation"), 10, 4);
         if (empty($form_meta)) {
             return $cart_item_meta;
         }
         require_once GFCommon::get_base_path() . "/form_display.php";
         $_POST['gform_submit'] = $_POST['gform_old_submit'];
         GFFormDisplay::process_form($form_id);
         $_POST['gform_old_submit'] = $_POST['gform_submit'];
         unset($_POST['gform_submit']);
         $lead = GFFormDisplay::$submission[$form_id]['lead'];
         $cart_item_meta['_gravity_form_lead'] = array();
         foreach ($form_meta['fields'] as $field) {
             if (isset($field['displayOnly']) && $field['displayOnly']) {
                 continue;
             }
             $value = RGFormsModel::get_lead_field_value($lead, $field);
             if (isset($field['inputs']) && is_array($field['inputs'])) {
                 foreach ($field['inputs'] as $input) {
                     $cart_item_meta['_gravity_form_lead'][strval($input['id'])] = $value[strval($input['id'])];
                 }
             } else {
                 $cart_item_meta['_gravity_form_lead'][strval($field['id'])] = $value;
             }
         }
         if (GFFormDisplay::$submission[$form_id]['is_valid']) {
             add_filter('add_to_cart_redirect', array(&$this, 'get_redirect_url'), 99);
             if (get_option('woocommerce_cart_redirect_after_add') == 'yes') {
                 $_SERVER['REQUEST_URI'] = add_query_arg(array('invalid' => 1));
             }
         }
         error_reporting($err_level);
     }
     return $cart_item_meta;
 }