[eluser]serhat[/eluser]
Obivously, I have 2 problems.
1. When I submit a checkbox form which is an array value and non-cheched form, It doesn't show me validation error such as 'this field is required'. It shows error when I check one of them. Normally it should have shown me even though I don't check anything on the form and just press submit.
2. How can I repopulate a checkbox as checked when I submit as checked. Think like set_value. In set_value it populates previous data. At this I want it to be auto checked when if I had submitted.
My controller
Code:
function preferences() {
$user = $this->ion_auth->user()->row();
$data['first_name'] = $user->first_name;
$data['last_name'] = $user->last_name;
$data['user_id'] = $user->id;
$data['address'] = $this->main_model->office_zip_match($user->zipcode);
$this->form_validation->set_rules('days[]', 'Days', 'required');
$this->form_validation->set_rules('contact[]', 'Contact', 'required');
if ($this->form_validation->run() == true) {
echo print_r($this->input->post());
} else {
$this->load->view('auth/preferences', $data);
}
}
My view
Code:
<div>Days to Deliver</div>
<?php echo form_open('signup/preferences'); ?>
<input type="checkbox" name="days[]" value="monday" id="days" /> Monday<br />
<input type="checkbox" name="days[]" value="tuesday" id="days" /> Tuesday<br />
<input type="checkbox" name="days[]" value="wednesday" id="days" /> Wednesday<br />
<input type="checkbox" name="days[]" value="thursday" id="days" /> Thursday<br />
<input type="checkbox" name="days[]" value="friday" id="days" /> Friday<br />
<div>How would you like us to contact you? (When package arrives / for all other issues</div>
<input type="checkbox" name="contact[]" value="email" id="contact" /> Email<br />
<input type="checkbox" name="contact[]" value="text" id="contact" /> Text<br />
<input type="checkbox" name="contact[]" value="cell" id="contact" /> Cell<br />
<div><input type="submit" value="Send" /></div>
<?php echo form_close(); ?>
<?php echo validation_errors(); ?>