douruduan8812 2018-08-17 13:11
浏览 67

如何将输入类型=“提交”替换为联系表格7上的按钮?

I have tried but it doesn't work.

remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_submit', 20 );<br>
add_action( 'wpcf7_init', 'wpcf7_add_shortcode_submit_button' );

function wpcf7_add_shortcode_submit_button() {
    wpcf7_add_shortcode( 'submit', 'wpcf7_submit_button_shortcode_handler' );
}

function wpcf7_submit_button_shortcode_handler( $tag ) {
    $tag = new WPCF7_Shortcode( $tag );

    $class = wpcf7_form_controls_class( $tag->type );

    $atts = array();

    $atts['class'] = $tag->get_class_option( $class );
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );

    $value = isset( $tag->values[0] ) ? $tag->values[0] : '';
    if ( empty( $value ) )
        $value = __( 'Send', 'contact-form-7' );

    $atts['type'] = 'submit';

    $atts = wpcf7_format`enter code here`_atts( $atts );

    $html = sprintf( '<button %1$s>%2$s</button>', $atts, $value );
    enter code here
    return $html;
}
  • 写回答

2条回答 默认 最新

  • drny60365 2018-08-17 13:50
    关注

    You can achieve this with easier way - jQuery:

    add_action('wp_footer',function(){
    echo '<script>
          jQuery(\'.wpcf7-form [type="submit"]\').attr("type","button");
          </script>';
    }, 9999);
    

    If you want to replace that input with custom button element, then you can do so

    add_action('wp_footer',function(){
    echo '<script>
          jQuery(\'.wpcf7-form [type="submit"]\').hide();
          jQuery(\'<button type="submit>BUTTON</button>"\').insertAfter(jQuery(\'.wpcf7-form [type="submit"]\'));
          </script>';
    }, 9999);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理