My Account

Forums

Forums General Select Field: Change / Add own data sources

Viewing 8 reply threads
  • Author
    Posts
    • #31344
      cubetech
      Participant

      Hello there

      Is it possible to add other data sources and/or remove existing data sources?
      Would be extremely helpful beeing able to do have some presets 🙂

    • #31345
      Mark Westguard
      Keymaster

      Hey!

      The presets dropdown loads from our CDN so they are fixed but if you have some suggestions for additional presets we could add we’d love to hear about that.

      In addition to presets, you can also import your own CSV files into the data grid area. To do that, either drag and drop the CSV file into the data grid area, or click the import icon.

      In future we’re planning on adding even more data sources, particularly for our integration add-ons.

      Mark

    • #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

    • #52351
      Kirsten Hoyte
      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.

      Ditto! We would love this ability!

      • #54421
        Olija Hasan
        Participant

        I second this, and add the ability to choose previous submission’s and previous submission field data as well in selects/dropdowns.

    • #52775
      cubetech
      Participant

      You can do this via hook and erase the already existing contents and prefill it with our own.
      Basically you can then prefill everything what you want 🙂

      Example:

      
      namespace ct_example;
      
      class WsForm
      {
          public static function Prefill($form)
          {
              $fieldId = 123;
              $matchingField = &wsf_form_get_field($form, $fieldId);
              wsf_field_rows_clear($matchingField);
      
              $prefillData = Helper::GetMyPrefillData(); // returns key/value pairs
              if ($prefillData) {
                  foreach ($prefillData as $prefillEntryKey => $prefillEntryValue) {
                      $row = (object)[
                          'default' => false, // you can create logic to preselect entries
                          'data' => [$prefillEntryValue, $prefillEntryKey] // you need to add the key/value fields to your dropdown!
                      ];
                      wsf_field_row_add($matchingField, $row);
                  }
              }
      
              return $form;
          }
      }
      add_filter('wsf_pre_render', ['\\' . __NAMESPACE__ . '\\WsForm', 'Prefill']);
      
    • #52985
      Kirsten Hoyte
      Participant

      Thanks. Actually, the wordpress hooks feature may be too advanced for me to use, and it doesn’t quite address my real need anyway (I don’t think). I wasn’t specific enough in my request. As someone who does not actually know how to do much (any) coding, I am searching for a way to easily pull data from an external data source into the data grids in my select fields without having to import a new csv file into the select fields each time my data changes.

      Using a csv stored in wordpress as a datasource would be ok as a last resort, but it doesn’t fully solve my problem because it would still require updating that csv in wordpress each time the data changes. What I really want is a simple way for my datasource to actually be a Google Sheet or possibly an Airtable. I had assumed that this might be possible with either the Zapier or the Google Sheets Add-on, but as I read the knowledge base, it seems as if both of those add-ons are more geared towards pushing the submitted form results out to other sources. Basically, I want to pull data from non wordpress sources into my select field, and I am hoping there is a no coding (or very light coding) was to do it. Thanks!

    • #52987
      Mark Westguard
      Keymaster

      Hi Kirsten

      That is the ultimate aim with our data source feature, we want to start extending the functionality of our add-ons so they have a data source allowing you to populate select, checkbox and radios with external data. We’re not quite there yet but that is on the development road map.

      MySQL query data source is also planned too.

      Thanks

      Mark

    • #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

    • #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;
      }
Viewing 8 reply threads
  • You must be logged in to reply to this topic.

Login