Welcome Guest, Not a member yet? Register   Sign In
Codeigniter multiple checkbox issue STRANGE!
#1

(This post was last modified: 01-07-2016, 03:52 AM by frobak.)

m using codeigniter and I have a very simple form, which has a few checkboxes:
Code:
<input type="checkbox" name="user_assign[]" value="' . $row->user_id . '">
Now, the values are definately getting posted because I can see them through firebug.
Code:
user_assign[]100002
user_assign[]100003
course_name Asbestos
But the below is empty? and i just dont understand?
Code:
$user_assign = $this->input->post('user_assign');
How is this possible?

Here is the controller:
PHP Code:
    function update_course_assignment_org() {
    
//print_r($_POST);

//print_r($this->input->post('user_assign')) ;

print_r$this->input->post()); 
    
        $this
->load->model('courses_model');
        $this->load->model('assignment_model');
    
        
// get course id from posted course name
        $course_name $this->input->post('course_name');
        $course_object $this->courses_model->get_course_id($course_name);
        $course_id $course_object[0]->course_id;
        
        
//$user_assign = substr(implode(', ', $this->input->post('user_assign')), 0);
        

        
//foreach ($this->input->post('user_assign') as $key => $value) {
            $test_obj = array(
               'course' => $user_assign,
               'users' => $course_id,
               'org' => $this->input->post('course_name')
            ); 
        //}        

        //$this->assignment_model->save_org_assignments($user_ids);
        
        $this
->template->write('title''Assignments');
        $this->template->write('navigation_strip'$this->load->view('navigation', array(), TRUE));         
        $this
->template->write('content'$this->load->view('/assignments/assign_test'$test_objTRUE));

        $this->template->render();        
        
    
    
}    

At the moment I am just trying to get the POST vars into the controller. Its just not working. I can echo/print the POST vars no problem. But I just cannot get the POST vars into the contoller with $this->input->post('user_assign')
Reply
#2

maybe you should show us more code...
Reply
#3

(01-07-2016, 03:38 AM)Avenirer Wrote: maybe you should show us more code...

added controller
Reply
#4

(This post was last modified: 01-07-2016, 04:08 AM by Avenirer.)

so... when you do a print_r($this->input->post('user_assign')); you get nothing?

I am asking this because in the controller you can't seem to use that $user_assign you are talking about...
Reply
#5

(01-07-2016, 04:05 AM)Avenirer Wrote: so... when you do a print_r($this->input->post('user_assign')); you get nothing?

Thats right, its NULL, empty

I've tried the following:

Code:
print_r($this->input->post('user_assign')) ;

NULL

Code:
print_r( $this->input->post());

NULL

Code:
$user_assign = substr(implode(', ', $this->input->post('user_assign')), 0);

NULL

Code:
foreach ($this->input->post('user_assign') as $key => $value) {

NULL
Reply
#6

(This post was last modified: 01-07-2016, 04:15 AM by Avenirer.)

This is rather impossible, unless there are no checkboxes selected (ticked).
Reply
#7

(01-07-2016, 04:15 AM)Avenirer Wrote: This is rather impossible, unless there are no checkboxes selected (ticked).

oh boy, don't I just know that. It makes absolutely no sense whatsoever.

Code:
print_r($_POST);

above code give outputs:

Code:
Array ( [user_assign] => Array ( [0] => 100002 [1] => 100003 ) [course_name] => Slips & Trips )

and when i try this:

Code:
print_r($this->input->post('user_assign'));

it outputs nothing. it empty?
Reply
#8

I have this thread on SO been going for a while. Everybody seems to be completely stumped. I mean what the hell is going on?

http://stackoverflow.com/questions/34643...kbox-issue
Reply
#9

I managed to get the data i wanted by using:

$assignmen = @$_POST['user_assign'];
Reply
#10

Not a good idea, as $_POST has no validation, and @ won't show the eventual errors you may get...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB