Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Userform - hidden forms with $Title

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 2120 Views
  • CHD
    Avatar
    Community Member
    218 Posts

    Userform - hidden forms with $Title Link to this post

    Hi,

    im using the userform, and i've created a function so that the same form appears on every page (instructions here: http://www.silverstripe.org/all-other-modules/show/267822?showPost=293032 )

    but now i would like to include a hidden field that captures that page that the form was submitted via, i dont think i can use $Title in the "hidden field" section of the admin, as thats not allowed.

    so i assumed i could place something like:

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

    to the template...but where?

    any help would be much appreciated.

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: Userform - hidden forms with $Title Link to this post

    Could you (and I am asking either you to look into it or "old & wiser") do something like this to display the form and other items and then add your value into it as requested...

    <% control MyForm %>
       <form $FormAttributes>
          <fieldset>
             <% control Fields %>
                <!-- do stuff to render form items -->
             <% end_control %>
          </fieldset>
          <!-- add your hidden field here -->
       </form>
    <% end_control %>

    the "do stuff to render form items" should be possible because FormField has ->forTemplate() method, I have done something like it before, so you should be able to do this. Hope this helps.

    Barry

  • JoshuaLewis
    Avatar
    Community Member
    76 Posts

    Re: Userform - hidden forms with $Title Link to this post

    I haven't tested this but my first guess would be to create a copy of /sapphire/templates/includes/Form.ss in the includes folder of your theme. Then between lines fourteen and fifteen add your hidden field, you'll probably need to place the title as $Top.Title to get the right value though.

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Userform - hidden forms with $Title Link to this post

    i tried that Joshua... the hidden field appears correctly in the form, but the value is blank.
    i tried $Title & $Top.Title - no luck.
    any ideas?

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Userform - hidden forms with $Title Link to this post

    also, when i replaced the value with "Test" that appears OK on the page (hidden) but doesn't come through in the email

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Userform - hidden forms with $Title Link to this post

    I would create a new field type and add that to the field, something along the lines of:

    /userforms/code/editor/CurrentPageField.php

    <?php
    class EditableCurrentHiddenPageField extends EditableFormField {

       static $singular_name = 'Current Page Hidden field';

       static $plural_name = 'Current Page Hidden fields';

       function getFormField() {
          return new HiddenField($this->Name, null, $this->Parent()->Title);
       }
    }

    EDIT: For easy upgrading etc., you would ideally place the additional code somewhere in the mysite/code folder, but it didn't seem to detect it running a quick test.

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Userform - hidden forms with $Title Link to this post

    cool!

    i think that makes sense to me... but i wont be able to test this until about 1 hour from now, so would you be able to add some more instructions for me??

    im worried when i try (and probably fail) you wont be online and i'll be stuck!

    thanks so much!

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Userform - hidden forms with $Title Link to this post

    OK!
    it worked...but it ALWAYS says services, because im repeating the form on EVERY page, but it originally resides on the "services" page...so how can i get it to pick up the page its appearing on, rather than the page it was made on?

    does that make sense?

    2120 Views
Page: 1 2
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.