Jump to:

23481 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Rendering Form When Link is Clicked

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

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

Page: 1
Go to End
Author Topic: 1112 Views
  • zenmonkey
    Community Member
    528 Posts

    Rendering Form When Link is Clicked Link to this post

    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 Page.ss 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)

  • dalesaurus
    Community Member
    283 Posts

    Re: Rendering Form When Link is Clicked Link to this post

    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.

  • boombox
    Community Member
    44 Posts

    Re: Rendering Form When Link is Clicked Link to this post

    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


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.