2017-05-05 3 views
0

Ich verwende Schwerkraftformulare, um Verkaufsanfragen an ein CRM zu senden.Füllen Sie das GravityForms-Feld automatisch mit rotierenden Werten

Wir haben 3 Verkäufer, die jeweils Anfragen in einer Rotation erhalten müssen.

Zum Beispiel:

  • Eintrag 1 - Tom
  • Eintrag 2 - Richard
  • Eintrag 3 - Harry
  • Eintrag 4 - Tom
  • Eintrag 5 - Richard
  • Eintrag 6 - Harry

Jedes Mal, wenn ein neuer Eintrag im Kontaktformular angezeigt wird, muss ein verborgenes Feld mit dem Namen des nächsten Vertriebsmitarbeiters in der Rotation eingefügt werden, um an unser CRM weitergeleitet zu werden.

Ich habe einige Erfahrung in PHP, aber nicht mit Gravity vertraut. Hoffentlich kann mir jemand in die richtige Richtung zeigen, um eine Lösung zu finden.

Antwort

0

Hier ist ein Beispiel dafür, wie dies zu tun:

/** 
* 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; 
}); 

Auch als Kern für die Nachwelt: https://gist.github.com/spivurno/8908a589aa6ceaf6ff0a874324bfbf93

Verwandte Themen