首页 > 解决方案 > Codeigniter 4 - 如何使用 form_checkbox?

问题描述

我不知道如何在 ci4 中使用 form_checkbox。我正在尝试为帖子制作更新表格。首先,页面读取数据并填充表单。发布后,如果有任何变化,它应该更新数据库。我在设置 bootstrap 4 切换时遇到问题(https://gitbrent.github.io/bootstrap4-toggle/

这是我的代码;

                    <label for="post_is_published">
                        <input type="hidden" name="post_is_published" value="0" data-off="Not Published">
                        <input 
                                data-toggle="toggle"
                                type="checkbox" 
                                name="post_is_published" 
                                id="post_is_published" 
                                value="1" 
                                <?php if(old('post_is_published', $post->post_is_published)): ?> 
                                    data-toggle='toggle' data-on="Published" 
                                <?php endif; ?> 
                        >
                        Is Published? 
                    </label>

如果为 1,则发布,如果为 0,则不发布。

标签: phpcodeigniter

解决方案


推荐阅读