【问题标题】:Contact Form 7 Change Form-Tag Output联系表格 7 更改表格标签输出
【发布时间】:2020-06-13 05:38:02
【问题描述】:

我正在尝试更改 contactform7 表单的输出

<form action="/#wpcf7-f583-p294-o1" method="post" class="wpcf7-form">

<form action="/#wpcf7-f583-p294-o1" method="post" class="small-12 column wpcf7-form" novalidate data-abide>

因此我添加了一些钩子

add_filter('wpcf7_form_class_attr', function($html_class) { return 'small-12 column ' . $html_class; }); // adds respsonsive classes to the form-tag
add_filter('wpcf7_form_novalidate', function($support_html5) { return true; }); // adds novalidate-attr to the form-tag

所以我唯一缺少的是数据属性。是否有任何钩子或任何想法,如何在不触及核心文件的情况下到达那里?

我发现 /contact-form-7/includes/contact-form.php 从第 297 行开始

/* Generating Form HTML */
public function form_html( $args = '' ) { // ...

然后,从第 409 行开始

$enctype = apply_filters( 'wpcf7_form_enctype', '' );
        ...

        $atts = array(
            'action' => esc_url( $url ),
            'method' => 'post',
            'class' => $class,
            'enctype' => wpcf7_enctype_value( $enctype ),
            'autocomplete' => $autocomplete,
            'novalidate' => $novalidate ? 'novalidate' : '',
        );

        ...
        $atts = wpcf7_format_atts( $atts );

        $html .= sprintf( '<form data-abide %s>', $atts ) . "\n";
        ...

        $html .= '</form>';
        $html .= '</div>';

SO:将我的值推送到 form_html 函数中的 atts 数组将是我的解决方案。但老实说,我不知道怎么做-

提前谢谢你!

【问题讨论】:

    标签: wordpress contact-form-7


    【解决方案1】:

    使用 jQuery。如果我正确阅读了您的问题...您正在尝试添加类small-12column...删除novalidate 并添加data-abide

    jQuery('#wpcf7-f583-p294-o1 form').addClass('small-12 column').removeAttr('novalidate').attr('data-abide', true);
    

    【讨论】:

    • 您好霍华德,感谢您的回复。我已经添加了 small-12 列和 novalidate 标记。现在缺少的是需要添加的 data-abide 属性。您的解决方案对我不起作用,因为它需要在 JS 呈现之前成为 HTML 的一部分 - 因此,遗憾的是,事后添加它对我来说不是解决方案。
    • 没有适合您的解决方案。在 form_html 函数中,$args 本身不能添加额外的 args。
    猜你喜欢
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    相关资源
    最近更新 更多