Pass form fields from application to view? |
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
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();
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
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;
basically you can just write everything in controller and just echo the html.
pro novice
(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.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |