We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Form Helper: Call to undefined function form_open()

Development and Programming

JCOGS Design's avatar
JCOGS Design
148 posts
4 years ago
JCOGS Design's avatar JCOGS Design

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.

       
Yuri's avatar
Yuri
315 posts
4 years ago
Yuri's avatar Yuri

I believe you need to include form helper

       
JCOGS Design's avatar
JCOGS Design
148 posts
4 years ago
JCOGS Design's avatar JCOGS Design

Hi Yuri. Thanks for the suggestion - I tried that but that simply generates a different error…

No such property: 'view' on ExpressionEngine\Legacy\Facade
       
Yuri's avatar
Yuri
315 posts
4 years ago
Yuri's avatar Yuri

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');

? 1
       
JCOGS Design's avatar
JCOGS Design
148 posts
4 years ago
JCOGS Design's avatar JCOGS Design

Ahah - that of course makes perfect sense (and works)!

Thanks Yuri!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.