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, biapar, Willr, Ingo, swaiba, simon_w

Different Forms using one template depending on URL action


Reply


3 Posts   550 Views

Avatar
copernican

Community Member, 189 Posts

27 January 2012 at 7:57am

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?

Avatar
MarcusDalgren

Community Member, 288 Posts

27 January 2012 at 10:09am

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.

Avatar
copernican

Community Member, 189 Posts

28 January 2012 at 3:12am

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.