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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Dynamically replace a form


Go to End


2 Posts   731 Views

Avatar
Xazen

Community Member, 18 Posts

17 February 2012 at 4:50am

Hi SilverStripe Community,

I want to create a contact page which can display different forms. On the right are <button/>-TAGs to switch between the forms.

For example my contact.ss looks like this and my page type has got the functions $FormOne and $FormTwo to return a form:

<div id="Form">
$FormOne
</div>

After I click on the 2nd button $FormOne should be replaced by $FormTwo.

Avatar
martimiz

Forum Moderator, 1391 Posts

18 February 2012 at 12:21am

Edited: 18/02/2012 12:22am

Looking at the options that I can think of:

1. have multiple forms on the page, and show the required one using JavaScript. Considerable overhead, not easy to implement the correct response to the form, spamprotection and stuff, so I wouldn't

2. if the button is pressed, reload the page with the desired form (?form=myform or implement a action/rule?)

3. use AJAX to dynamically load the desired form into some container. Maybe falling back to (2) when no javascript available.

Oh... and the simplest: just have separate pages, each with their own form, replace the custom buttons by a submenu... :-)