Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果未选中复选框,则回显文本_Php_Wordpress_If Statement_Checkbox - Fatal编程技术网

Php 如果未选中复选框,则回显文本

Php 如果未选中复选框,则回显文本,php,wordpress,if-statement,checkbox,Php,Wordpress,If Statement,Checkbox,我有以下复选框表格: <p> <label class="mtt" for="serie_mark"><h1><?php _e( 'Options', 'randomtheme' ); ?></h1></label> <input type="radio" name="code_name" id="supi1" value="supi1" <?php echo ( series_get_meta( 'code_n

我有以下复选框表格:

<p>
<label class="mtt" for="serie_mark"><h1><?php _e( 'Options', 'randomtheme' ); ?></h1></label>
<input type="radio" name="code_name" id="supi1" value="supi1" <?php echo ( series_get_meta( 'code_name' ) === 'supi1' ) ? 'checked' : ''; ?>>
<label for="supi1"><?php _e( 'Option 1', 'randomtheme' ); ?></label><br>
<input type="radio" name="code_name" id="pishti6" value="pishti6" <?php echo ( series_get_meta( 'code_name' ) === 'pishti6' ) ? 'checked' : ''; ?>>
<label for="pishti6"><?php _e( 'Option 2', 'randomtheme' ); ?></label><br>
<input type="radio" name="code_name" id="recky2" value="recky2" <?php echo ( series_get_meta( 'code_name' ) === 'recky2' ) ? 'checked' : ''; ?>>
<label for="recky2"><?php _e( 'Option 3', 'randomtheme' ); ?></label><br>
</p>

if ( isset( $_POST['code_name'] ) )
update_post_meta( $post_id, 'code_name', esc_attr( $_POST['code_name'] ) );




如果(isset($\u POST['code\u name'])) 更新发布元数据($发布id,'代码名称',esc属性($发布['代码名称']);
如果选中了某个复选框,我将使用以下脚本显示一条消息:

<?php if($testing = series_get_meta('code_name')) { 
if ($testing == 'supi1') {
echo 'My text';
} elseif ($testing == 'pishti6') {
echo 'Another text';
} elseif ($testing == 'recky2') {
echo 'Some other text';
} else {
echo 'This is the default text for nothing selected';
} } ?>


一切都很好,它确实注册和显示信息,除了一件事。。。如果未选中复选框,则不会显示默认消息。你知道怎么做吗?谢谢。

您需要更改if条件

if($testing = series_get_meta('code_name')) { 
    if ($testing == 'supi1') {
        echo 'My text';
    } elseif ($testing == 'pishti6') {
        echo 'Another text';
    } elseif ($testing == 'recky2') {
        echo 'Some other text';
    } 
} else {
    echo 'This is the default text for nothing selected';
} 

也许使用JavaScript。您可以在客户端执行此操作。如果未选中复选框,则我假设
series\u get\u meta
返回falsy值。如果未选中任何选项,则
series\u get\u meta
返回falsy值。然后它将不会进入if块内部,并且所有代码都不会执行。因此,创建
if($testing=series\u get\u meta('code\u name'))的else