2013-10-18 51 views

回答

0
add_filter("gform_confirmation_4", "custom_confirmation", 3, 4); 
function custom_confirmation($confirmation, $form, $lead, $ajax) 

給出自定義確認。每個字段值可以通過使用$鉛[{字段ID}]

0

檢索我有一個解決方案基於使用表單提交掛鉤和GForms API的組合。這是一個可怕的插件,所以我爲邏輯流程的混亂道歉。使用框架方法非常重要,而不是自己處理數據,因爲存在大量黑客行爲以及正在進行的匹配字段ID等問題。

我將提供一個解決方案,將一個表單提交以預先填充另一個表單。更改POST數據的目的地非常簡單,他們在gform_form_taghook documentation page上有一個例子。是的,這是真正做到這一點的唯一方法。

此處不再贅述。我已經設定,工作過的形式配置,使事情變得更簡單爲最終用戶,所以它的工作原理是這樣的:

  • 選擇「允許現場動態地填充」在你的目標表單字段的高級設置,選擇每個參數的名稱。
  • 在其他表單的源字段上添加匹配的CSS類以設置關聯。
  • 將CSS類添加到源表單本身,以便我們可以快速檢查重定向是否必要。

$class = 'GForms_Redirector'; 

add_filter('gform_pre_submission', array($class, 'checkForSubmissionRedirection'), 10, 1); 
add_filter('gform_confirmation', array($class, 'performSubmissionRedirection'), 10, 4); 

abstract class GForms_Redirector 
{ 
    const SOURCE_FORMS_CLASS_MATCH = 'submission-redirect'; 
    const DEST_PAGE_SLUG = 'submit-page-slug'; 
    const DEST_FORM_ID = 1; 

    protected static $submissionRedirectUrl; 

    // first, read sent data and generate redirection URL 
    function checkForSubmissionRedirection($form) 
    { 
     if (false !== preg_match('@\W' . self::SOURCE_FORMS_CLASS_MATCH . '\[email protected]', $form['cssClass'])) { 
      // load page for base redirect URL 
      $destPage = get_page_by_path(self::DEST_PAGE_SLUG); 

      // load form for reading destination form config 
      $destForm = RGFormsModel::get_form_meta(self::DEST_FORM_ID, true); 
      $destForm = RGFormsModel::add_default_properties($destForm); 

      // generate submission data for this form (there seem to be no hooks before gform_confirmation that allow access to this. DUMB.) 
      $formData = GFFormsModel::create_lead($form); 

      // create a querystring for the new form based on mapping dynamic population parameters to CSS class names in source form 
      $queryVars = array(); 
      foreach ($destForm['fields'] as $destField) { 
       if (empty($destField['inputName'])) { 
        continue; 
       } 

       foreach ($form['fields'] as $field) { 
        if (preg_match('@(\s|^)' . preg_quote($destField['inputName'], '@') . '(\s|$)@', $field['cssClass'])) { 
         $queryVars[$destField['inputName']] = $formData[$field['id']]; 
         break; 
        } 
       } 
      } 

      // set the redirect URL to be used later 
      self::$submissionRedirectUrl = get_permalink($destPage) . "?" . http_build_query($queryVars); 
     } 
    } 

    // when we get to the confirmation step we set the redirect URL to forward on to 
    function performSubmissionRedirection($confirmation, $form, $entry, $is_ajax = false) 
    { 
     if (self::$submissionRedirectUrl) { 
      return array('redirect' => self::$submissionRedirectUrl); 
     } 

     return $confirmation; 
    } 
} 

如果你想通過查詢字符串別的地方傳遞表單值,那麼你只需要在回調切出我的代碼,並建立自己的URL重定向到。

相關問題