1794 Posts in 590 Topics by 562 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1293 Views |
-
Display Form using Shortcode

22 September 2010 at 4:11am
Hi,
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: http://ssbits.com/2-4-using-short-codes-to-embed-a-youtube-video/ 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?
Thanks
Johannes -
Re: Display Form using Shortcode

2 October 2010 at 2:43am
Ok, for anyone interested:
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!
Johannes
-
Re: Display Form using Shortcode

9 August 2011 at 11:41pm
Thanks X75. To make it even easier for others here is some sample code:
Presuming the form is generated in function ShowYourForm, in the YourForm class add:
public static function YourFormShortCodeHandler($arguments, $content = null, $parser = null) {
$current = Controller::curr();
return $current->ShowYourForm()->forTemplate();
}In _config.php add:
ShortcodeParser::get()->register('YourForm',array('YourForm','YourFormShortCodeHandler'));
In the CMS editor include
[YourForm]
-
Re: Display Form using Shortcode

10 August 2011 at 12:48am
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?
-
Re: Display Form using Shortcode

24 November 2011 at 1:09pm
um......what?
OK, this is exactly what I want to do to!!!!! But I'm not quite piecing it together here :0(
Would it be possible for anyone to provide a mostly complete working example of how this all goes? A basic short code contact/feedback form perhaps? Please please pllllleeeeeease?
I didn't quite get this part:
"Add it's output to the dataarray passed to $template->process. "I've implemented the YouTube shrotcode handler fine no problem but if I could get this one working it would be GREAT!
Thanks
-
Re: Display Form using Shortcode

29 November 2011 at 11:00pm
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)
Martine
| 1293 Views | ||
|
Page:
1
|
Go to Top |



