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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

All forms shall use Form.ss, but not the cms. How ?


Go to End


6 Posts   3419 Views

Avatar
Allisone

Community Member, 27 Posts

1 May 2009 at 12:46pm

I have modified the Form.ss and copied my modified version into my templates folder.
Now this form.ss is used for the login form, for the password forgotten and the user defined form. But also in the cms, which produces strange effects.

Is there a way to solve this ? I mean it shall be used everywhere in the frontend, but simply not in the cms, thats all.
I see that this kind of thing has been discussed several times, but each time the problem was slightly different.

Thanks for help in advance

PS: I know, that I can change $Form in my Page.ss to
<% if Form %>
<% include myForm %>
<% end_if %>
But the login form comes with $Content, which doesn't seem to be an object, so that I can't stop it using the default form.ss. Which again is either not my desired form.ss or my own form.ss which than again is used by the cms too :(

Avatar
Nathan Cox

Community Member, 99 Posts

31 May 2009 at 1:47pm

Hi, I realise this is an old post but I just spotted it and thought I'd share my solution to this problem.
I basically made a form extension that has an isFrontend() method that checks the URL to see if we're in admin. There's probably a much better way to do that bit but it works for now. Anyway, then I overwrote Form.ss and put in an if statement - if isFrontend(), then include PageForm.ss (which goes in your theme's includes folder) else use HTML I copied and pasted from the original Form.ss.

Not perfect I'm sure but so far it seems to work. I've attached a zip of the relevant files, but you still need to make your own PageForm.ss with whatever layout code you want.

Attached Files
Avatar
Allisone

Community Member, 27 Posts

4 June 2009 at 6:07am

Hey thanks, that helped.
There were some defects in your code and I had to modify and add some code.
However, your idea is a great solution :D more than enough for me :D

Also my Silverstripe didn't want to take the form.ss from your Includes-Directory, but it works fine when my modified PageForm.ss and the default(/cms) Form.ss are in my themes/Includes directory.

Hope others will find this helpfull, too

Cheers

Avatar
Nathan Cox

Community Member, 99 Posts

4 June 2009 at 9:49am

Glad it helped, and yes in this case my line of thinking was better than my code :)

I'm not sure why it wasn't reading Form.ss for you though, it works fine for me keeping Form.ss in the form_template module...

Avatar
Allisone

Community Member, 27 Posts

4 June 2009 at 11:09am

I use the user defined form module, too. Maybe that's interfering somehow ?!

Avatar
Nathan Cox

Community Member, 99 Posts

4 June 2009 at 1:48pm

Actually I'm thinking the problem is the name of the module - SS reads through the modules alphabetically, so since form_template comes before sapphire, sapphire's form.ss is overriding it.

I didn't have this problem because I extracted this code from a larger module called xfm_extensions...so if you renamed this to template_forms or something that comes after "s" it should work.