gpt4 book ai didi

php - 在 Contact Form 7 上使用图像作为单选按钮

转载 作者:太空宇宙 更新时间:2023-11-04 08:18:20 28 4
gpt4 key购买 nike

我正在尝试创建一个选项,供人们选择 WP CF7 表单中的图像。因为他们只能选择一个选项,所以在我看来,使用单选按钮功能是最好的方法。我在 https://wpquestions.com/Need_Image_as_a_Radio_Button_in_Contact_Form_7/19618#answer_16362 上找到了一个代码示例但是添加代码确实 a) 不会在管理部分创建标签,并且 b) 只返回页面上的完整短代码,而不是返回所需的图像。

我确实找到了这个 How to make custom form-tag in contact form 7 required在这个论坛上。我尝试添加

add_action( 'wpcf7_init', 'wpcf7_add_form_tag_imageradio' );

但它返回了以下错误:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'wpcf7_add_form_tag_imageradio' not found or invalid function name in /home2/clay/public_html/wp-includes/class-wp-hook.php on line 298

关于如何解决这个问题的任何想法?使用的主题是 OnePage Express

最佳答案

你需要把两个论点:

function add_shortcode_imageradio() {
wpcf7_add_shortcode( 'imageradio', 'imageradio_handler', true );
}
add_action( 'wpcf7_init', 'add_shortcode_imageradio' );

function imageradio_handler( $tag ){
$tag = new WPCF7_FormTag( $tag );

$atts = array(
'type' => 'radio',
'name' => $tag->name,
'list' => $tag->name . '-options' );

$input = sprintf(
'<input %s />',
wpcf7_format_atts( $atts ) );
$datalist = '';
$datalist .= '<div class="imgradio">';
foreach ( $tag->values as $val ) {
list($radiovalue,$imagepath) = explode("!", $val
);

$datalist .= sprintf(
'<label><input type="radio" name="%s" value="%s" class="hideradio" /><img src="%s"></label>', $tag->name, $radiovalue, $imagepath
);

}
$datalist .= '</div>';

return $datalist;
}

不要忘记 CSS:

input.hideradio{ /* HIDE RADIO */
visibility: hidden; /* Makes input not-clickable */
position: absolute; /* Remove input from document flow */
}
.imgradio label > input + img{ /* IMAGE STYLES */
cursor:pointer;
border:2px solid transparent;
}
.imgradio label > input:checked + img{ /* (RADIO CHECKED) IMAGE STYLES */
border:2px solid #f00;
}

并使用在 contactform7 的 FORM 选项卡内声明的新简码:

[imageradio radio-312 
"Value1!http://[YourImgUrl]"
"Value2!http://[YourImgUrl]"
]

在例子中Need Image as...他们错过了包含“add_action”,仅此而已

可以查看CF7 doc还有

希望有帮助!

关于php - 在 Contact Form 7 上使用图像作为单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45740637/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com