Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Rendering Form When Link is Clicked

Go to End

3 Posts   1606 Views


Community Member, 545 Posts

30 October 2009 at 3:56am

I'm trying to create an "email this link to a friend" form. Right now the the form is rendered into a hidden div and revealed in a model dialog box. Thats fine an dandy, but I'd like to get the form to render either on its own page or the page in question when an "email this page" link is clicked much like the login form works.

Right now the best solution I can think of is to Create a new with the form where I want it to render and create a RenderWithTemplate function in my Page class and just reload the page with the new template. But this seems a little convoluted.

Is there a more elegant solution? Perhaps using ModelAsController (I'm having trouble finding an adequate description od how this workd in the documentation)


Community Member, 283 Posts

30 October 2009 at 7:06am

Either way you'll probably want to break out your Form into a separate control in your Page_Controller (The forms tutorial covers this). A slick experience would be to use a modal to present the form inline.

Oh, and I just happened to do a writeup on that!
I've gotten a lot of mileage out of using forms inside of modals, very handy.

Also, I've also had some troubles figuring out exactly how to make ModelAsController work. It hasn't yet been beaten into submission.


Community Member, 44 Posts

6 December 2010 at 11:09pm

I have followed the tutorial on how to create a simple form to use on any page on the site

I have gone through the tutoral to use a modal window to display content

I'm having a little trouble with rendering the form view in a model dialog box as wondering if you can provide guidance on this

The code I am using is

public function ajaxShowForm() {
if( Director::is_ajax() ) {
return $this->renderWith('InfoForm',$return);

Where InfoForm is the form function which works when called as <% include InfoForm %> on a template