• Resolved torkeller

    (@torkeller)


    I have a CF7 form with a select field for the recipient. With “default: get” i can select a line in the dropdown from a parameter in the calling URL.
    So far so good.
    But now I would like to generate the drop-down list dynamically (via the ‘wpcf7_form_tag’ hook in functions.php). This also works. But no longer the default choice from the calling URL.
    What can I do?
    (And by the way: If the select field is a recipient field, at design time it must contain an valid address, else a “illegal syntax” message is trown.)
    [select* empfaenger include_blank default:get
    “xyz|[email protected]”]

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

    (@torkeller)

    I was able to identify the problem.
    In select.php, the the URL parameter (symbolic e-mail name) is compared with the e-mail addresses (array $values), not with the e-mail labels (array $labels):

    Instead of:
    ` foreach ($values as $key => $value) {
    if ( $hangover ) {
    $selected = in_array( $value, (array) $hangover, true );
    } else {
    $selected = in_array( $value, (array) $default_choice, true );
    }
    $item_atts = array(
    ‘value’ => $value,
    ‘selected’ => $selected ? ‘selected’ : ”,
    );
    I changed it to:
    foreach ($labels as $key => $value) {

    Now it works as expected.

    • This reply was modified 5 years, 2 months ago by torkeller.
Viewing 1 replies (of 1 total)

The topic ‘Default value in dynamically generated select field?’ is closed to new replies.