Am working on a simple add-on that generates a form using the following call to the View service:
$form = ee('View')->make('my_addon:my_form')->render($my_vars);
Where my_form
contains this kind of content:
<?=form_open($return_path)?>
<?=form_fieldset()?>
<?=form_input(array('name' => 'field_1', 'id' => 'field_', 'dir' => 'ltr', 'maxlength' => 6, 'autocomplete' => 'off', 'required' => ''))?>
<?=form_fieldset_close()?>
<?=form_fieldset('',array('class' => 'last'))?>
<?=form_submit('submit',$btn_label, 'class="'.$btn_class.'" data-work-text="'.$btn_working.'" '.$btn_disabled)?>
<?=form_fieldset_close()?>
<?=form_close();?>
The form is initially generated after a hook - cp_member_login
- and renders perfectly first time around.
The form is configured to capture some input and send it to an EE Action (/?ACT=...
) to be evaluated.
If the input is evaluated to be correct processing continues without problem.
However if the input is incorrect, the process calls for the form to be regenerated (with an error message) and redisplayed so the user can have another go… The redisplayed form is generated using the same block of code that generates the initial form, but when it is run EE throws an error:
Call to underfined function form_open()
I’m trying to work out why this is happening, and what I need to do to get the form to redisplay if required.
As far as I can tell, the only difference between the two instances is the URL.
The hook used to start the process fires during the creation of a CP page (login/authenticate) which is (I am guessing) why the form renders first time around.
Second time around the form is being generated for a non-CP url (…/?ACT=40)
My guess is that the View service only works on CP pages (doesn’t say this in docs - at least I can’t find it saying this - but I’ve only ever seen View used for CP page generation) and the second URL is therefore throwing things out; but I am unclear on how I tell EE to treat the second time around as a CP page - but maybe there is a way to trigger an ACT style event from ‘within’ a CP page? Or maybe I’m just doing it all wrong.
Would value any thoughts on how to resolve this issue.
If you’re doing this inside ACT request, you’ll also need to load view library (since view is really CP stuff, it’s not generally intended for the site frontend)
ee()->load->library('view');
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.