【问题标题】:How can i get custom switch checkbox value in CodeIgniter?如何在 CodeIgniter 中获取自定义开关复选框值?
【发布时间】:2020-05-15 04:25:51
【问题描述】:

这里是我的编辑模式:

<form autocomplete="off" novalidate
    action="<?= base_url('app/admin/user-editData')?>"
    method="POST">
    <input type="hidden"
        name="<?=$this->security->get_csrf_token_name();?>"
        value="<?=$this->security->get_csrf_hash();?>">

    <div class="form-group">
        <div class="controls">
            <label>Phone Number</label>
            <input type="text" name="PhoneNo"
                class="form-control"
                value="<?= $data1->PhoneNo; ?>"
                placeholder="<?= $this->lang->line('enter');?> <?= $this->lang->line('phonenumber');?>"
                required
                data-validation-required-message="<?php echo $this->lang->line('required');?>"
                data-validation-containsnumber-regex="(\d)+"
                minlength="11" maxlength="13"
                data-validation-containsnumber-message="<?php echo $this->lang->line('valid_numeric');?>">
        </div>
    </div>
    <div class="form-group">
        <div
            class="custom-control custom-switch custom-switch-success switch-md mr-2 mb-1">
            Mobile Activated
            &nbsp;
            <input type="checkbox" class="custom-control-input"
                id="customSwitch80">
            <label class="custom-control-label"
                for="customSwitch80">
                <span class="switch-text-left"
                    value="Y"><?= $this->lang->line('yes');?></span>
                <span class="switch-text-right"
                    value="N"><?= $this->lang->line('no');?></span>
            </label>
        </div>
    </div>
    <div class="form-group">
        <div
            class="custom-control custom-switch custom-switch-success switch-md mr-2 mb-1">
            Website Activated
            &nbsp;
            <input type="checkbox" class="custom-control-input"
                id="customSwitch0">
            <label class="custom-control-label"
                for="customSwitch0">
                <span class="switch-text-left"
                    value="Y"><?= $this->lang->line('yes');?></span>
                <span class="switch-text-right"
                    value="N"><?= $this->lang->line('no');?></span>
            </label>
        </div>
    </div>
    <div class="modal-footer">
        <button type="submit"
            class="btn btn-primary"><?= $this->lang->line('save');?></button>
    </div>
</form>

我有一个名为 WebActivated 和 MobileActivated 的数据库字段。

例子:

WebActivated 状态在数据库中为“Y”(枚举 Y 或 N 数据类型)

模态打开时如何将开关置于“是”位置?

然后我将状态变为“否”,那么我如何将值“N”存储在数据库中?

抱歉英语不好。如果我错了,请纠正我

【问题讨论】:

    标签: php jquery codeigniter


    【解决方案1】:

    您必须检查checkbox 状态何时更改,然后调用ajax 以更新database 中的值。

     $('#customSwitch0').change(function () {
        if ($(this).prop("checked")) { // checked
            var check = 'Y';
    
        }else{ // not checked
            var check = 'N';
        }
        $.ajax({ // start ajax call
            url: "<?php your-url-here ?>", // location to your controller, update table there, and return 1 or 0(Json values)
            dataType: "JSON",  // expects json to be returned
            method: "POST", 
            data: {'check': check} // send the value to be updated, will be accessible through $this->input->post('check');
            success: function(msg){
                // check condition for success or fail ie. 1 or 0
                // do something here
            }
        });
    });
    

    更新的移动代码相同 (id = customSwitch80)
    看看对你有没有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-14
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2019-06-23
      相关资源
      最近更新 更多