【问题标题】:Contact form 7 custom options value联系表格 7 自定义选项值
【发布时间】:2015-02-25 10:17:39
【问题描述】:

我在 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 操作它们。

有什么解决方法吗?

【问题讨论】:

  • 应该改变 DOM 中的值。你能展示一下你对管道做了什么吗?
  • 我只是把` [select menu-1 id:select_box "Option 1|opt1" "Option 2|opt2" "Option 3|opt3"], and that's it. But when I looked in the DOM, there were still Option 1 etc. in the value` 放在了。我现在以不同的方式对其进行了排序,但仍然如此。
  • @dingo_d 你是怎么排序的?我很想拥有类似的功能。
  • 我不认为我已经解决了这个问题。我最终在 php 和 jquery 中针对特定选项制定了解决方法,因为我是为客户做的。

标签: jquery wordpress contact-form-7


【解决方案1】:
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);

【讨论】:

  • 您好,欢迎来到 stackoverflow,感谢您的回答。虽然这段代码可能会回答这个问题,但您是否可以考虑添加一些解释来说明您解决了什么问题,以及您是如何解决的?这将有助于未来的读者更好地理解您的答案并从中学习。
猜你喜欢
  • 1970-01-01
  • 2016-01-05
  • 2014-05-16
  • 2016-08-06
  • 1970-01-01
  • 2021-11-14
  • 2017-06-23
  • 2018-06-09
  • 2013-09-01
相关资源
最近更新 更多