samedi 9 février 2019

Update checkbox Codeigniter

My Controller :

public function update($id)
{
    $data['tag'] = $this->Tag_model->get_all();
    $data['gambar'] = $this->Gambar_model->get_by_id($id);
    $this->load->view('gambar/gambar_edit', $data);
}

public function update_action()
{
    $this->_rules();

    if ($this->form_validation->run() == FALSE) {
        $this->update($this->input->post('id_gambar'));
    } else {
        $data = array(
            'judul_gambar' => $this->input->post('judul_gambar', TRUE),
            'judul_tag' => implode(', ', $this->input->post('judul_tag', TRUE)),
            'img_gambar' => $this->input->post('img_gambar', TRUE)
         );

         $this->Gambar_model->update($this->input->post('id_gambar'), $data);
         $this->session->set_flashdata('flash', 'diubah');
         redirect('gambar');
    }
}

My View :

<?= form_open('gambar/update_action') ?>
            <div class="form-group col-lg-8">
              <input type="hidden" class="form-control" id="idgambar" name="id_gambar" value="<?= $gambar['id_gambar'] ?>">
              <label for="judulgambar">Nama</label>
              <input type="text" class="form-control" id="judulgambar" name="judul_gambar" value="<?= $gambar['judul_gambar'] ?>">
              <small class="form-text text-danger font-italic"><?= form_error('judul_gambar') ?></small>
            </div>
            <div class="form-group col-lg-8">
              <label for="imggambar">Gambar</label>
              <input type="text" class="form-control" id="imggambar" name="img_gambar" value="<?= $gambar['img_gambar'] ?>">
              <small class="form-text text-danger font-italic"><?= form_error('img_gambar') ?></small>
            </div>
            <div class="form-group pl-3">
              <?php foreach ($tag as $row): ?>
                <div class="form-check-inline">
                    <input class="form-check-input" type="checkbox" name="judul_tag[]" value="<?= $row['judul_tag'] ?>">
                    <label class="form-check-label" for="gridCheck">
                      <?= $row['judul_tag'] ?>
                    </label>
                </div>
              <?php endforeach; ?>
              <small class="form-text text-danger font-italic"><?= form_error('judul_tag[]') ?></small>
            </div>
            <button type="submit" class="btn btn-success ml-3" name="submit">Ubah</button>
          <?= form_close() ?>

I want to ask how I can get checked on my checkbox was submitted when I want to do update. I just get value on input text not for checked checkbox. I was search it's must be explode the value but I don't know where it supposed to be I very appreciate it for your help, thanks




Aucun commentaire:

Enregistrer un commentaire