I want to be able to embed a form in any page by using a short code. For example let's say the shortcode [feedback] is suppost to embedd a feedback form.
I got the shortcode working based on: [url]http://ssbits.com/2-4-using-short-codes-to-embed-a-youtube-video/[/url] but I can't figure out, how to display and process a form in the shortcode handler.
I tried adding a function feedbackform to my page_controller and then call it from the template that i use to render the shortcode, but it does not show up. I guess the page_controller is not the right place, but where would I put the form?
Add the function that creates the form to your page_controller.
In the shortcode handler function use Controller::curr() to get a reference to the controller and call the function.
Add it's output to the dataarray passed to $template->process.
Thanks to the silversripte irc channel for the help!
Just wondering whether it's also possible to include the results of the processing of the form (e.g. function UserAction($data, $form)) from the same (or a different) short code handler? Anyone any ideas?
I've just recently completed something like this: a simple course-subscription form (using a custom template) that can be instantiated either from template or from a shortcode.
On submission it sets a session value and redirects, after which it again reads the session value (and clears it). Based on the session value it uses a custom template to either show the form or a success message. Basically very simple: just like you would normally go about creating a custom form, the only real extra is a very simple shotcode handler.
I documented it somewhat extensively in my logs: http://www.balbuss.com/custom-form-and-shortcode/ Have a look if you want (and let me know if there's anything missing)