2017-05-05 43 views
0

我正在使用重力形式向CRM發送銷售查詢。自動填充具有旋轉值的GravityForms字段

我們有3個銷售人員,每個人需要輪流接收查詢。

例如:

  • 條目第1 - 湯姆
  • 條目2 - 理查德
  • 條目3 - 哈里
  • 條目4 - 湯姆
  • 條目5 - 理查德
  • 條目6 - Harry

每次聯繫表單上有一個新條目時,我需要包含一個隱藏字段,其中包含下一個銷售人員的姓名,以便傳遞給我們的CRM。

我有一些PHP的經驗,但不熟悉Gravity。希望有人能指引我找到正確的解決方案。

回答

0

這裏是如何做到這一點的例子:

/** 
* Gravity Wiz // Gravity Forms // Rotating Values 
* http://gravitywiz.com/ 
*/ 
add_filter('gform_entry_post_save', function($entry) { 

    // Specify an array of values that will be rotated through. 
    $rotation = array('Tom', 'Richard', 'Harry'); 

    // Specify the form ID for which this functioanlity applies. 
    $form_id = 1722; 

    // Specify the field ID in which the current rotation value will be saved. 
    $field_id = 1; 

    /* DON'T EDIT BELOW THIS LINE */ 

    // Bail out of this is not our designated form. 
    if($entry['form_id'] != $form_id) { 
     return $entry; 
    } 

    // Get the last submitted entry. 
    $last_entry = rgar(GFAPI::get_entries($entry['form_id'], array('status' => 'active'), array('direction' => 'desc'), array('offset' => 1, 'page_size' => 1)), 0); 

    // Get the value submitted for our designated field in the last entry. 
    $last_value = rgar($last_entry, $field_id); 

    // Determine the next index at which to fetch our value. 
    $next_index = empty($last_value) ? 0 : array_search($last_value, $rotation) + 1; 
    if($next_index > count($rotation) - 1) { 
     $next_index = 0; 
    } 

    // Get the next value based on our rotation. 
    $next_value = $rotation[ $next_index ]; 

    // Update the value of our designated field in the database. 
    GFAPI::update_entry_field($entry['id'], $field_id, $next_value); 

    // Update the value of our designated field in the $entry object that will be used to continuing processing the current submission. 
    $entry[ $field_id ] = $next_value; 

    return $entry; 
}); 

也可作爲後人一個要點:https://gist.github.com/spivurno/8908a589aa6ceaf6ff0a874324bfbf93