Welcome Guest, Not a member yet? Register   Sign In
Not receiving post data
#1

[eluser]pyronate[/eluser]
Hello!
I am having trouble getting my post data from the view to the controller.

I have a function in the controller that obtains data (checkbox and their IDs of those checked) but it does not seem to be getting any of the data, $this->input->post('components') is returning false from within the controller once it is called from the form in the view.

What am I doing wrong? Do I need to be including something so they can "communicate"?

Here's some snippet of code so you guys know what's going on:

view:
Code:
<form action="data/process_action/" action="post">
...
<input type="hidden" name="test" value="should work" />
<input type="checkbox" name="components[]" value="<?php echo $entry['ComponentID'];?>" />
...
</form>

controller:
Code:
function process_action(){
   echo "processing action... </br>";
   echo $this->input->post('test');
        
   $values = $this->input->post('components');
        
   foreach($values as $value){
      echo "CompValue: $value <br />";
   }
}

Right now, I'm just trying to get the id's printed out, ideally, I'm trying to setup database calls to delete selected items from the database. All that is being printed out in the controller is "processing action..." and then the message "Invalid argument supplied for foreach()", presumably because it is not receiving the POST data.
#2

[eluser]Crimp[/eluser]
Have a look at this great tool for learning CI:

$this->output->enable_profiler(TRUE);

Put that at the top of your process_action function.

It will show the $_POST global (and more), if present, after you hit submit.

Also, have a look at the form helper and form_validation class of CI.

And you are using a checkbox array with only one checkbox?

And unchecked checkboxes do not show.
#3

[eluser]tonanbarbarian[/eluser]
$this->input->post('components'); will return false if nothing is returned, which is what will happen if the checkbox is not checked
#4

[eluser]pyronate[/eluser]
Yes, I have a bunch of component rows, I have only shown one, all of them have the name="components[]". Crimp, thanks for the tip, I tried outputting, however, under POST DATA, it is telling me none exists. So somehow from the form to the form processing page, the POST data is getting lost.
#5

[eluser]pyronate[/eluser]
I figured out the problem, so apparently it had to do something with the form submit URL, didn't seem to play nicely with the URL rewriting, but it seems that the form_helper produced the correct URL.
#6

[eluser]pyronate[/eluser]
What's the best way to delete a bunch of id's from a table using the $this->db->delete function? The components[] is as such:

Code:
Array
(
    [0] => 57
    [1] => 58
    [2] => 56
    [3] => 38
    [4] => 46
    [5] => 34
    [6] => 52
    [7] => 53
    [8] => 44
    [9] => 49
    [10] => 41
    [11] => 43
    [12] => 45
    [13] => 47
    [14] => 48
    [15] => 50
    [16] => 51
    [17] => 55
    [18] => 39
    [19] => 37
)

What's the best way to generate the SQL query DELETE from components where id=57 etc... using code igniter?




Theme © iAndrew 2016 - Forum software by © MyBB