0

I have form fields which are checkboxes as below :

<input id="[email protected]" type="checkbox" checked="checked" value="[email protected]" style="float:left;border:2px dotted #00f" name="email[]">
<input id="[email protected]" type="checkbox" checked="checked" value="[email protected]" style="float:left;border:2px dotted #00f" name="email[]">
<input id="[email protected]" type="checkbox" checked="checked" value="[email protected]" style="float:left;border:2px dotted #00f" name="email[]">

But when in the controller I am taking a var_dump($this->input->post('email')) , it displays bool(false) .

in the controller I have this method :

public function referral_email()
{
    $data = $this->input->post('email');
    var_dump($data);exit;
 }

How to access this array of checkboxes in my controller ?

13
  • Can you post your controller code? Commented Oct 19, 2011 at 21:12
  • I have updated just now @Colin Commented Oct 19, 2011 at 21:19
  • How/Where are you loading your view? Commented Oct 19, 2011 at 21:24
  • I am loading my view from a different controller . And the form data is getting submitted to this controller. Commented Oct 19, 2011 at 21:27
  • Not sure if this helps, but your id="" attribute probably shouldn't have an '@' character in it. Commented Oct 19, 2011 at 21:29

3 Answers 3

1

Are you by any chance trying to trim the output using the form validation library? I had the same problem, and removing 'trim' from the validation rules solved it.

Sign up to request clarification or add additional context in comments.

1 Comment

Bingo @Talha...that was exactly what I was doing...thanks for the solution buddy.
0

Make sure the form tag surrounding the text boxes has the attribute method="post" or else it might be submitting to the $_GET array. I got it to work with the following code:

Controller

public function referral_email()
{
    $data = $this->input->post('email');
    var_dump($data);
}

View

<form method="post" action="welcome/referral_email">
<input id="[email protected]" type="checkbox" checked="checked" value="[email protected]" style="float:left;border:2px dotted #00f" name="email[]">
<input id="[email protected]" type="checkbox" checked="checked" value="[email protected]" style="float:left;border:2px dotted #00f" name="email[]">
<input id="[email protected]" type="checkbox" checked="checked" value="[email protected]" style="float:left;border:2px dotted #00f" name="email[]">
<input type="submit" value="Submit" />
</form>

Comments

0

trim() works on strings, but your $_POST['email'] is an array. The correct fix should be to pass the field name as 'email[]' when using the form validation library (in the code you didn't show us but commented on later).

http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#arraysasfields

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.