当前位置: 首页>>代码示例>>PHP>>正文


PHP GFFormDisplay::replace_save_variables方法代码示例

本文整理汇总了PHP中GFFormDisplay::replace_save_variables方法的典型用法代码示例。如果您正苦于以下问题:PHP GFFormDisplay::replace_save_variables方法的具体用法?PHP GFFormDisplay::replace_save_variables怎么用?PHP GFFormDisplay::replace_save_variables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GFFormDisplay的用法示例。


在下文中一共展示了GFFormDisplay::replace_save_variables方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: submit_form

 /**
  * 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;
 }
开发者ID:fjbeteiligung,项目名称:development,代码行数:93,代码来源:api.php


注:本文中的GFFormDisplay::replace_save_variables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。