![]() |
Pass form fields from application to view? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: Pass form fields from application to view? (/showthread.php?tid=75714) |
Pass form fields from application to view? - Isterklister - 03-09-2020 Hi, my question: is it possible to pass a hole form field from application to a view? Example: In the view I want to print out a drop down field, PHP Code: form_dropdown('project_type_id', $drop, NULL) PHP Code: echo $form1; Why? I have a lot of form fields to display. These are dynamically created from a database and the view file does not know what type of field it is. I can of course send information about that but it will be simple just to echo one variable than som switch statement and all form field types output. /Pelle RE: Pass form fields from application to view? - includebeer - 03-09-2020 Yes, you can save the output of form_dropdown to a variable: PHP Code: $html_form = form_dropdown(...); And you can create the whole form: PHP Code: $html_form = form_open(...) . form_dropdown(...) . form_submit(...) . form_close(); RE: Pass form fields from application to view? - Isterklister - 03-09-2020 Thank you! The code in view will be much much better. Working simple example: In controller: PHP Code: $array_with_options = array('1' => 'First option', '2' => 'Second option'); In view: PHP Code: echo $html_form; RE: Pass form fields from application to view? - tweenietomatoes - 03-09-2020 basically you can just write everything in controller and just echo the html. RE: Pass form fields from application to view? - includebeer - 03-09-2020 (03-09-2020, 07:27 AM)tweenietomatoes Wrote: basically you can just write everything in controller and just echo the html. Yes but it’s not best practice to echo directly in controller and it doesn’t follow the MVC pattern. For a quick test or for debugging it’s ok we all do it. But for the rest, it’s always better to create a view. |