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:

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

User forms: Show $UserDefinedForm inside Page(url-segment)


Go to End


11 Posts   6962 Views

Avatar
Richie

Community Member, 18 Posts

29 August 2009 at 12:31am

Edited: 29/08/2009 12:33am

<% control Page(order-form) %>
 $UserDefinedForm
<% end_control %>

I also tried $Form but both with no result. $Content gives the value of the content field ($UserDefinedForm) instead of the user form.
Do I have to create a custom method for this?

Any ideas? Thanks!

Avatar
Richie

Community Member, 18 Posts

3 September 2009 at 2:33am

I added this function to the Page class

	function ShowForm(){
		$get = DataObject::get_one('SiteTree', "URLSegment = 'order-form'");
		return new UserDefinedForm_Controller($get);
	}

And inside my template

	  <% control ShowForm %>
	   $Form
	  <% end_control %>

Avatar
gocreative

Community Member, 17 Posts

14 May 2010 at 12:09am

Hi guys,

This has been really helpful. The only problem is, when I added the code to my template file (\themes\mytheme\templates\Layout\Page.ss), it adds the form to every page of the site. How do I set the form to only show on a particular page?

(This is my first SS installation so please forgive my ignorance)

Cheers,

Grant

Avatar
CHD

Community Member, 219 Posts

23 September 2010 at 5:33am

This is AWESOME.
and useful for lots of other features, not just forms :)

thanks.

Avatar
JoshuaLewis

Community Member, 81 Posts

30 September 2010 at 9:17am

Edited: 30/09/2010 9:17am

The next question is how to make the form reload the same page after submission instead of mysite.com/(url-segment)/finished. And to do so with the success message in place of the form.

Avatar
CHD

Community Member, 219 Posts

1 October 2010 at 3:43am

thats a good question...

also, i would like a hidden field on the form that generates the page title (e.g - $Title) so that i know which page/category the form was submitted via.

does anybody know how i can do this?
i took a look at the template files for userform, but it looks a bit more complex than i was hoping.

i figured i could just add:

<input type="hidden" name="Page" value="$Title" />

to the template...but where?

Avatar
JoshuaLewis

Community Member, 81 Posts

1 October 2010 at 6:09am

Edited: 01/10/2010 6:09am

The redirect is coming from line756 of userforms/code/UserDefinedForm.php at the end of the process() method of UserDefinedForm_Controller.

The best solution I have right now is to subclass UserDefinedForm and overwrite process() keeping everything the same except for that last line which gets replaced with whatever logic is needed, possibly even a call to another method. This is a kludge though so if anyone has a solution that doesn't involve recreating process() in its entirety I'd love to hear it.

Avatar
MagicUK

Community Member, 60 Posts

26 July 2011 at 9:36pm

Big thanks to Richie for that code!

Go to Top