联系表7自定义选项值

问题描述 投票:1回答:1

我正在CF7中使用选择简码创建下拉列表。问题是我在<option>标记中的值与选项的名称相同,例如

<select id="#selection">
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>
</select>

我想有自己的选择。现在,我尝试使用pipes,但这并没有在DOM中明显改变该值。我需要显示不同的值,以便可以使用jQuery操作它们。

任何解决方法?

jquery wordpress contact-form-7
1个回答
0
投票
add_filter("wpcf7_form_tag", function($scanned_tag, $replace){


    if ("selection" === $scanned_tag["name"]) {

        $contact_form = WPCF7_ContactForm::get_current();

        $number_of_posts = $contact_form->shortcode_attr("number_of_posts");
        $post_type = $contact_form->shortcode_attr("post_type");


        // using $number_of_posts and $post_type here


        $scanned_tag['raw_values'] = [
            //"number_of_posts \"$number_of_posts\" - post_type \"$post_type\" | Option",
              "op1 | Option 1",
            "op2|Option 2",
            "op3|Option 3",
        ];



        $pipes = new WPCF7_Pipes($scanned_tag['raw_values']);

        $scanned_tag['values'] = $pipes->collect_befores();
        $scanned_tag['pipes'] = $pipes;

    }


    return $scanned_tag;

}, 10, 2);
© www.soinside.com 2019 - 2024. All rights reserved.