Di sini modal edit saya:

<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>

Saya memiliki bidang basis data yang disebut WebActivated dan juga MobileActivated.

Contoh:

Status WebActivated adalah "Y" dalam database (enum Y atau N tipe data)

Bagaimana saklar di posisi "ya" ketika modal dibuka?

Kemudian saya swith status menjadi "tidak" lalu bagaimana saya bisa menyimpan nilai "N" dalam database?

Maaf untuk bahasa Inggris yang buruk. koreksi saya jika saya salah

0
pohon gems 15 Mei 2020, 07:25

1 menjawab

Jawaban Terbaik

Anda harus memeriksa kapan status checkbox diubah dan kemudian melakukan panggilan ajax untuk memperbarui nilai di 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
        }
    });
});

Kode yang sama untuk seluler yang diperbarui (id = customSwitch80)
Lihat apakah itu membantu Anda.

0
sauhardnc 15 Mei 2020, 04:45