Advertisement
sepehr125

GForm

Feb 1st, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. add_filter( 'gform_field_input', 'gform_cart_subsection', 10, 5 );
  2. add_action( 'gform_pre_submission', 'pre_submission_handler' );
  3. add_filter( 'gform_entry_field_value', 'category_names', 10, 4 );
  4.  
  5. // gform_cart_subsection() targets a field with CSS class "subsection" and rewrites it with a number of
  6. // input fields: one input per post ID stored in the $favs array.
  7.  
  8. function gform_cart_subsection($input, $field, $value, $lead_id, $form_id) {
  9.  
  10.     if( $field["cssClass"] == "subsection" ) {
  11.        
  12.     $favs = wpfp_get_users_favorites(); // This gives an array of post ID's
  13.    
  14.         $input = "<br />";
  15.  
  16.     foreach ( $favs as $fav ){
  17.             $input .= '<label for="fav' . $fav . '">' . get_the_title($fav) . '</label><input name="field_4[]" id="fav' . $fav . '" type="text" value="Add note..."><br/>';
  18.         }
  19.     }
  20.  
  21.         return $input;
  22. }
  23.  
  24.  
  25. function pre_submission_handler($form){
  26.  
  27.     $_POST["input_4"] = json_encode($_POST["input_4"]);
  28.  
  29. }
  30.  
  31. function category_names($value, $field, $lead, $form){
  32.  
  33.     if(  $field['id'] == 4 ) {
  34.  
  35.         $newvalue = '';
  36.         $choices = json_decode($value, true);
  37.    
  38.             foreach($choices as $choice) {
  39.                 $new_value .= '<li>'.$choice.'</li>';
  40.             }
  41.    
  42.             return '<ul>' . $new_value . '</ul>';
  43.  
  44.     } else {
  45.  
  46.         return $value;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement