Getting results from view to the controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Getting results from view to the controller (/showthread.php?tid=31068) |
Getting results from view to the controller - El Forum - 06-05-2010 [eluser]RobertB.[/eluser] Hello guys, I can't figure out how to do this if is not hard code. Hard Code to send what the user selected by email. This work good. View Code: <input type="checkbox" name="ase" value="1" /> ASE Code: $ase = $this->input->post('ase'); But if I try to do this Dynamic Code: <?php foreach($certifications as $row => $cert):?> Code: [ASE] => 1 [ATRA] => 2 Do I have to do another foreach in the controller? Thanks Getting results from view to the controller - El Forum - 06-05-2010 [eluser]RobertB.[/eluser] How can I do this Code: $this->email->message( Thanks Getting results from view to the controller - El Forum - 06-05-2010 [eluser]cahva[/eluser] For the first question, make the checkbox field names as array. Like: Code: <input type="checkbox" name="certification[<?=$cert->certification?>]" value="<?=$cert->id?>" /> <?=$cert->certification?> With a name like that, you can use foreach on $_POST['certification']. The latter error with the email.. You are actually echoing $cat inside $this->email->message(). Also making any kind of loop in the middle of variable setting is not allowed. So dont You dont have to foreach the $categories['category']. Just use implode() function. So if you wanted to add categories separated by comma, you would do it like this: Code: $this->email->message( Getting results from view to the controller - El Forum - 06-05-2010 [eluser]RobertB.[/eluser] cahva, thanks a lot that was what I needed Getting results from view to the controller - El Forum - 06-07-2010 [eluser]RobertB.[/eluser] Hey cahva, I'm sorry that I keep asking this php basic questions but I now I have this problem. If the user don't select any of the check boxes I get an empty variable and an error Code: implode() [function.implode]: Invalid arguments passed I've tried In the form and the controller but no luck Code: value="<?=(isset($cert->id)) ? $cert->id : '0'?>" Can u please show me how can I go about this Thanks again Getting results from view to the controller - El Forum - 06-15-2010 [eluser]daelsepara[/eluser] Assuming you followed cahva's lead: Code: <input type="checkbox" name="certification[<?=$cert->certification?>]" value="<?=$cert->id?>" /> <?=$cert->certification?> It's probably better if you do a foreach, in case no checkbox was selected, as you did originally. Code: $categories_list = ""; Getting results from view to the controller - El Forum - 06-16-2010 [eluser]RobertB.[/eluser] Thanks, daelsepara. This is what I end up doing and is working. Please let me know if I should not do it this way Code: if($this->input->post('category')){ Thanks again, Robert Getting results from view to the controller - El Forum - 06-16-2010 [eluser]daelsepara[/eluser] that will work well too. cheers! |