Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » All forms shall use Form.ss, but not the cms. How ?

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

Page: 1
Go to End
Author Topic: 2171 Views
  • Allisone
    Avatar
    Community Member
    27 Posts

    All forms shall use Form.ss, but not the cms. How ? Link to this post

    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

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: All forms shall use Form.ss, but not the cms. How ? Link to this post

    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
  • Allisone
    Avatar
    Community Member
    27 Posts

    Re: All forms shall use Form.ss, but not the cms. How ? Link to this post

    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 more than enough for me

    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

    Attached Files
  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: All forms shall use Form.ss, but not the cms. How ? Link to this post

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

  • Allisone
    Avatar
    Community Member
    27 Posts

    Re: All forms shall use Form.ss, but not the cms. How ? Link to this post

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

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: All forms shall use Form.ss, but not the cms. How ? Link to this post

    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.

    2171 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.