Advertisement
chrishajer

Convert list field to CSV string

Jun 5th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2. // Help Scout 24815
  3. // process list field 9 (only) into a CSV string to pass to Sugar CRM
  4. // initialize an empty string to hold field 9 array items
  5. $field_9_as_csv = '';
  6. // you have to use a Gravity Forms hook which passes in the $entry to use this code
  7. foreach ($entry as $key => $value) {
  8.         // the $entry array key begins with a 9, our list field
  9.         if (substr($key, 0, 1) == '9') {
  10.                 // if there is a $value for this array key, i.e. not empty
  11.                 if (strlen($value) > 0) {
  12.                         $field_9_as_csv = $field_9_as_csv . $value . ', ';
  13.                 }
  14.         }
  15. }
  16. // strip final trailing comma and one space (two characters)
  17. $field_9_as_csv = substr($field_9_as_csv, 0, -2);
  18. // send $field_9_as_csv to Sugar CRM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement