Jump to:

23576 Posts in 19403 Topics by 2893 members

General Questions

SilverStripe Forums » General Questions » Different Forms using one template depending on URL action

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: 532 Views
  • IOTI
    Avatar
    Community Member
    189 Posts

    Different Forms using one template depending on URL action Link to this post

    Hi,

    I'm currently working on a project that involves a lot of different forms that are shown in a modal box. For each form I want to show I am using the renderWith() function to show a different template. This is resulting in me having to create a lot of templates that only have a $FormFunction variable on them.

    Is there a way I can use one template that will somehow load the form I want to use?

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Different Forms using one template depending on URL action Link to this post

    If you don't need different templates then why are you using different templates? Is it because the name of the $FormFunction differs? If so you should be able to setup a function that returns $FormFunction->forTemplate() which is what happens when $FormFunction is called in the template. Either that or some other kind of intermediary function that decides what form to render without setting a different template.

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Different Forms using one template depending on URL action Link to this post

    yes, its because the $FormFunction differs for each form i want to show.

    This is where I'm stuck though, I can't figure out how to setup the intermediary function, at least easily.

    //using url_variables to call this function when a certain action is used
    public function showCustomFormA(){
          return $this->renderWith(array('FormPopup', 'Popup'));
       }

    //using url_variables to call this function when a certain action is used
    public function showCustomFormB(){
          return $this->renderWith(array('FormPopup', 'Popup'));
       }
       
    // want to use this to return my desired form
       public function FormForPopup(){
             
       }
       
       public function CustomFormA(){
    ...form code...
    return $form;
    }

       public function CustomFormB(){
    ...form code...
    return $form;
    }

    and my FormPopup.ss template would just have

    $FormForPopup

    How can I get FormForPopup() to return my form without using a bunch of if or switch statements that check which action is being used? This is probably simple but i'm unsure of how to best approach it. perhaps my approach so far is completely wrong.

    532 Views
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.