0

Hi all I have a few checkboxes in Codeigniter, eg:

$data = array(
    'name'        => 'newsletter',
    'id'          => 'newsletter',
    'value'       => 'accept',
    'checked'     => TRUE,
    'style'       => 'margin:10px',
    );

echo form_checkbox($data);

eg produces:

<input type="checkbox" name="newsletter" id="newsletter" value="accept" checked="checked" style="margin:10px" />

is there a way that I can check in codeigniter whether the box has been selected or not in my controller? if I use $this->input->post('newsletter') and the box has been selected will the value be false? if so how can I run form validation on the data?

TotalNewbie
  • 1,004
  • 5
  • 13
  • 25

2 Answers2

0

$data = $this->input->post('newsletter') gives you the value of the checkbox that was selected.

You may also go through the following links:

  1. Get checkbox values in CodeIgniter.

  2. Checking checkbox value

Community
  • 1
  • 1
Vagabond
  • 877
  • 1
  • 10
  • 23
0

the checkbox value is empty when this component is unchecked, you want see the data use:

print_r($_POST)

you can see all the string passed in the post method

clairerb6
  • 99
  • 8