21474 Posts in 5781 Topics by 2620 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 356 Views |
-
Different Forms using one template depending on URL action

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?
-
Re: Different Forms using one template depending on URL action

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.
-
Re: Different Forms using one template depending on URL action

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.
| 356 Views | ||
|
Page:
1
|
Go to Top |


