Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter qbaas

    (@qbaas)

    Thanks for asking!

    In the contact form, I have:

    [select* your-coach class:cf7-field data:vccoach placeholder “Coach”]</label>

    In functions.php, this is the corresponding part:

    add_filter('wpcf7_form_tag_data_option', function($n, $options, $args) {
      if (in_array('vccoach', $options)){
        $coaches = getCoaches();
        return $coaches;
      }
      return $n;
    }, 10, 3);

    getCoaches() is a method that gets data from an external API endpoint.

    In that method I construct a new array from the JSON output by the external API endpoint, consisting of ID’s and Names. In a foreach loop through the response, this code:

    array_push($coaches, $coach['Id'] . '|' . $coach['Name']);

    … builds an array that consists of entries like :
    [“024|John Doe”,”026|Joan Does”, …]

    But the result of this, is 024|John Doe and 062|Joan Does … as options in the contact form select field, so the Pipe character isn’t interpreted like it is in strings literals.

    What am I missing? Thanks again for any help!

Viewing 1 replies (of 1 total)