图像作为联系表格 7 中的复选框选项
Image as a checkbox option in Contact Form 7
我想使用图像作为签入联系表 7 的选项。我搜索并找到了使用单选按钮执行此操作的方法。我在代码中做了更改,它确实作为一个复选框工作,但它在提交表单时只发送一个值,而不是多个值。
这是我正在使用的代码。请告诉我需要更改的内容。
function add_shortcode_imagecheckbox() {
wpcf7_add_shortcode( 'imagecheckbox', 'imagecheckbox_handler', true );
}
add_action( 'wpcf7_init', 'add_shortcode_imagecheckbox' );
function imagecheckbox_handler( $tag ){
$tag = new WPCF7_FormTag( $tag );
$atts = array(
'type' => 'checkbox',
'name' => $tag->name,
'list' => $tag->name . '-options' );
$input = sprintf(
'<input %s />',
wpcf7_format_atts( $atts ) );
$datalist = '';
$datalist .= '<div class="imgcheckbox">';
foreach ( $tag->values as $val ) {
list($checkboxvalue,$imagepath) = explode("!", $val
);
$datalist .= sprintf(
'<label><input type="checkbox" name="%s" value="%s" class="hidecheckbox" /><img src="%s"></label>', $tag->name, $checkboxvalue, $imagepath
);
}
$datalist .= '</div>';
return $datalist;
}
有点晚了,但我现在遇到了这个问题
在输入名称中添加[]
$datalist .= sprintf(
'<label><input type="checkbox" name="%s[]" value="%s" class="hidecheckbox" /><img src="%s"></label>', $tag->name, $checkboxvalue, $imagepath
);
我想使用图像作为签入联系表 7 的选项。我搜索并找到了使用单选按钮执行此操作的方法。我在代码中做了更改,它确实作为一个复选框工作,但它在提交表单时只发送一个值,而不是多个值。
这是我正在使用的代码。请告诉我需要更改的内容。
function add_shortcode_imagecheckbox() {
wpcf7_add_shortcode( 'imagecheckbox', 'imagecheckbox_handler', true );
}
add_action( 'wpcf7_init', 'add_shortcode_imagecheckbox' );
function imagecheckbox_handler( $tag ){
$tag = new WPCF7_FormTag( $tag );
$atts = array(
'type' => 'checkbox',
'name' => $tag->name,
'list' => $tag->name . '-options' );
$input = sprintf(
'<input %s />',
wpcf7_format_atts( $atts ) );
$datalist = '';
$datalist .= '<div class="imgcheckbox">';
foreach ( $tag->values as $val ) {
list($checkboxvalue,$imagepath) = explode("!", $val
);
$datalist .= sprintf(
'<label><input type="checkbox" name="%s" value="%s" class="hidecheckbox" /><img src="%s"></label>', $tag->name, $checkboxvalue, $imagepath
);
}
$datalist .= '</div>';
return $datalist;
}
有点晚了,但我现在遇到了这个问题
在输入名称中添加[]
$datalist .= sprintf(
'<label><input type="checkbox" name="%s[]" value="%s" class="hidecheckbox" /><img src="%s"></label>', $tag->name, $checkboxvalue, $imagepath
);