• Resolved Moogie17

    (@moogie17)


    Hi again Roland – thanks for all your help with my first project using PDb a couple of months ago. I now have another project for which your awesome plugin is ideal and have a quick question if I may:

    I need to populate a multi-select checkbox field from some Advanced Custom Field on a Custom Post Type.

    Following your tutorial at https://xnau.com/populate-a-form-dropdown-from-the-database/ and modifying it with my WP query to get the data, I have successfully used pdb-form_element_build_multi-checkbox to set the checkbox labels as needed. I notice that the values of the checkboxes are the same as the labels and wondered if there is a way to set this in the same function?

    I have tried a couple of things like:

     $field->options = $options;
      $field->values = $values;

    (where values is an array of the values)

    which didn’t work, and then tried
    $options[] = $event_name."-".$event_dates. "-".$event_city."::".$event_code;
    in the hope that using the :: label/value separator might do the trick, but no joy.

    Is there a way to set the values as well as the labels when using pdb-form_element_build_ ? Or do I need to construct a custom form element for this?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author xnau webdesign

    (@xnau)

    In the original tutorial code, after you get your data, you are building it as an array in the foreach loop. To set up labels and values, when you are building your array, you need to put the label as the key for each value, so your array will end up as something like:

    array( 'title1 => 'value1', 'title2' => 'value2' );

    Thread Starter Moogie17

    (@moogie17)

    Many thanks Roland, that’s perfect!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘pdb-form_element_build_ setting options *and* values?’ is closed to new replies.