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

Dynamically replace a form


2 Posts   339 Views


17 February 2012 at 4:50am Community Member, 18 Posts

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 looks like this and my page type has got the functions $FormOne and $FormTwo to return a form:

<div id="Form">

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


18 February 2012 at 12:21am (Last edited: 18 February 2012 12:22am), Forum Moderator, 1091 Posts

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... :-)