My Account

Forums

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: Select Field: Change / Add own data sources #66232
    Dan Dickson
    Participant

    For reference, here is some sample code to dynamically pull data using a filter hook. I got hung up on the nested arrays.

    add_filter( 'wsf_test_data_source_hook', 'wsf_test_data_source_hook_callback', 10, 3 );
    function wsf_test_data_source_hook_callback( $data_grid, $field_id, $form_object ) {
        if( $field_id !== 325) { return $data_grid; }
    	global $wpdb;
        $data_grid[ 'columns' ] = array(
            array( 'label' => __( 'name' ) ),
            array( 'label' => __( 'email' ) )
        );
    	
    	$results = $wpdb->get_results("SELECT name,email FROM directory", ARRAY_A);
    	
        $data_grid[ 'groups' ] = array(
            array(
                'label' => __('data'),
                'rows' => array(
                    array(
                        'data' => array()
                    )
                )
            )
        );
    
    	
    	foreach ($results as $result)
    	{
    		$data_grid['groups'][0]['rows'][] = array('data' => array(
    					$result['name'],
       					$result['email']));
    	}
    	
        return $data_grid;
    }
    in reply to: Select Field: Change / Add own data sources #66111
    Dan Dickson
    Participant

    Mark,

    Any update to the SQL data source for fields function? I’m about to start a new project and will have to revisit this issue again.

    Thanks

    Dan

    in reply to: Select Field: Change / Add own data sources #33071
    Dan Dickson
    Participant

    It would be really handy if we could pull the data dynamically from a SQL table or a static csv file hosted locally when the form loads, I thought I made a feature request for that before but I cannot seem to find it now.

    Thanks

Viewing 3 posts - 1 through 3 (of 3 total)