如何将多个选择复选框保存到wp选项表wordpress中 [英] How to save multiple select checkbox into wp option table wordpress

查看:56
本文介绍了如何将多个选择复选框保存到wp选项表wordpress中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
for($i=1;$i<4; $i++){
 if ( isset( $_POST['user'] ) ) {
                    $options['user'] = esc_html( $_POST['user'.$i.''] );
                } else {
                    $options['user'] = '';
                }
                update_option('iwmp_settings', $options);
}

$options = get_option('iwmp_settings');

        if( $options != '' ) {

            $user.$i = $options['user'.$i.''];
		}
        ?>
<div class="container">
    <div class="row">
        
				<div class="form-group">
					<input name="user<?php echo $i;?>" type="checkbox" id="user<?php echo $i;?>" value="1" <?php checked( $options['user'.$i.''], 1 ); ?> />editor<br>
					<input name="user<?php echo $i;?>" type="checkbox" id="user<?php echo $i;?>" value="2" <?php checked( $options['user'.$i.''], 2 ); ?> />author<br>
					<input name="user<?php echo $i;?>" type="checkbox" id="user<?php echo $i;?>" value="3" <?php checked( $options['user'.$i.''], 3 ); ?> />subscriber<br>

				</div>
			 
	    
    </div>
</div>





我的尝试: < br $> b $ b



What I have tried:

<?php
for($i=1;$i<4; $i++){
 if ( isset( $_POST['user'] ) ) {
                    $options['user'] = esc_html( $_POST['user'.$i.''] );
                } else {
                    $options['user'] = '';
                }
                update_option('iwmp_settings', $options);
}

$options = get_option('iwmp_settings');

        if( $options != '' ) {

            $user.$i = $options['user'.$i.''];
		}
        ?>
<div class="container">
    <div class="row">
        
				<div class="form-group">
					<input name="user<?php echo $i;?>" type="checkbox" id="user<?php echo $i;?>" value="1" <?php checked( $options['user'.$i.''], 1 ); ?> />editor<br>
					<input name="user<?php echo $i;?>" type="checkbox" id="user<?php echo $i;?>" value="2" <?php checked( $options['user'.$i.''], 2 ); ?> />author<br>
					<input name="user<?php echo $i;?>" type="checkbox" id="user<?php echo $i;?>" value="3" <?php checked( $options['user'.$i.''], 3 ); ?> />subscriber<br>

				</div>
			 
	    
    </div>
</div>

推荐答案

i = 1;


i< 4;


i ++){
if (isset(
i++){ if ( isset(


这篇关于如何将多个选择复选框保存到wp选项表wordpress中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆