making a form to work - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: making a form to work (/showthread.php?tid=55257) |
making a form to work - El Forum - 10-17-2012 [eluser]entropy[/eluser] I have a big problem with making a form work. I use a controller to handle a registration request. When I strip de controller down to this: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); It seems to me that making a form with the form helper is just impossible. Either that, or else: What am I doing wrong? making a form to work - El Forum - 10-17-2012 [eluser]entropy[/eluser] I found the solution. The form code must be placed in a view that is loaded by the controller. controller: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); view: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); making a form to work - El Forum - 10-17-2012 [eluser]PhilTem[/eluser] You're absolutely right: Your every code for a view (what is to be displayed on the client side) must be put in a view and loaded with Code: $this->load->view('path/to/view', $data); to display it at the proper position. Your code posted in the OP doesn't work because of the way CI_Loader::view() works: It starts a buffer and includes your view file, then flushing the buffer to get the content and setting as the output-response. If you use echo (which, by the way, you should never use in a controller - that's what views are made for) in your controller it will not get caught by the buffer and since the final outputs is passed to the client as the last thing done your code will appear on the very top of the generated source thus before the <head>-tag making a form to work - El Forum - 10-17-2012 [eluser]CroNiX[/eluser] All CI output is buffered (views). If you echo from a controller, that gets output before the views get sent out, no matter the order in the code (all echos go out realtime, all views get sent out at the end of processing). The only way around that is to manually set the output (instead of echo) using the output class in the controller, or just use views. |