Hi all i am newbie for Codeigniter framework. I would handle medicine prescription module in hospital management system. So there is one multiple checkbox field in prescription add form, and that contains values of Morning,Afternoon,Night. So i had a little confusion to how to create Controller,Model and View.
I cannot understand the array concept when store the values to database. So i can develop the checkbox to store values separately. But there is another issue found in that way, if i want to edit the checkbox value in edit page, the checkboxes are not checked when i am editing the form in edit page.
So i want to store the values in one column and display the checkboxes are checked when i am in edit page. ie). If i checked the Morning and Night checkbox, in database it stores Morning,Night. And edit page also checked the two checkboxes.
I could see many example doubts like as mine in our community, but i cannot clear my issue. So kindly give a right way for solve my issue.
Here is my View: <div class="form-group row"> <label for="timings" class="col-xs-3 col-form-label">Timings<i class="text-danger">*</i></label>
<label><input type="checkbox" name="mor" id="time" value="Morning"/> Morning</label> <label><input type="checkbox" name="aftr"id="time" value="Afternoon"/> Afternoon</label> <label><input type="checkbox" name="nit" id="time" value="Night"/> Night</label> </div>
Here is my Model:
private $table = "prescription";
public function create($data = []) {
return $this->db->insert($this->table,$data); }
And my Controller:
form validation:
$this->form_validation->set_rules('mor', 'Morning', ''); $this->form_validation->set_rules('aftr','Afternoon',''); $this->form_validation->set_rules('nit','Night','');
and Create prescription is:
if ($this->input->post('id',true) == null) {
$data['prescription'] = (object)$postData = [
'id' => $this->input->post('id',true),
'mor' => $this->input->post('mor',true),
'aftr' => $this->input->post('aftr',true),
'nit' => $this->input->post('nit',true),
];
and Update is:
else { // update prescription
$data['prescription'] = (object)$postData = [
'id' => $this->input->post('id',true),
'mor' => $this->input->post('mor',true),
'aftr' => $this->input->post('aftr',true),
'nit' => $this->input->post('nit',true),
];
Thank you.
Aucun commentaire:
Enregistrer un commentaire