PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Pre Populate from CSV

  1. Do you guys know how to prepopulate a dropdown from a csv file on the server?

    I would do it through the admin area, but the file is 30,000+ lines so that admin interface freezes when I try to save the form.

    This is what I attempted with, but no luck

    add_filter('gform_pre_render_7', 'GF_prepopulate_2');
    function GF_prepopulate_2($form){
    		 foreach($form["fields"] as &$field){
                if($field["id"] == 15){
    					$csv = array();
    					$file = fopen('http://example.com/mf.csv', 'r');
    
    					while (($result = fgetcsv($file)) !== false)
    					{
    						$csv[] = $result;
    					}
    					fclose($file);
    
    					foreach ($csv as $line){
    								$field['choices'][] = array( 'text' => $line, 'value' => $line);
    							}
    				}
    			}
    	 return $form;
    	}
    Posted 6 years ago on Thursday June 13, 2013 | Permalink