External Form Controller set view variables

Permalink 3 users found helpful
I thought I'd share this since I couldn't find it anywhere else on the forums and it took me a while to figure out.

I'm using the form helper to build my external form, but I'd like to set some variables in the controller before the page gets viewed. The function to call to set variables for use in external forms is: on_page_view()


View Replies:
CBknits replied on at Permalink Reply
Thank you so much! I have been looking for this information for hours!

I am developing an external form called "sample"
I created a custom table named "Dictionary" in my database and put data in it.

In "public_html/blocks/external_form/forms/sample.php" I was able to access the data variables using
$db = Loader::db();
$r = $db->Execute('select col1, col2 from Dictionary');

and the data variables showed up when rendered.

However, I could not figure out why the same code didn't work in the controller, "/public_html/blocks/external_form/forms/controllers/sample.php". I tried putting it inside several different functions, including the "public function view() {...here...}" but nothing worked until I finally found your post. This is what worked:
public function on_page_view(){ 
   $db = Loader::db();
   $r = $db->Execute('select col1, col2 from Dictionary');
   $this->set('qqq', $r)

Then back in the view file, "public_html/blocks/external_form/forms/sample.php" I can use the variable "$qqq" and it actually shows up when rendered.

glockops replied on at Permalink Reply
You wouldn't by any chance know what other functions are available in external forms?

I'm looking for the equivalents on_start and on_before_render. Are these available in external forms?

And for others stumbling across this, your form action must have action_ in front of it. Examine the form action and controller action for the test_form for details.