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.

All other Modules /

Discuss all other Modules here.

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

Userform - hidden forms with $Title

Go to End

11 Posts   2874 Views


Community Member, 218 Posts

1 October 2010 at 3:46am


im using the userform, and i've created a function so that the same form appears on every page (instructions here: )

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.


Forum Moderator, 1848 Posts

1 October 2010 at 5:17am

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>
<% control Fields %>
<!-- do stuff to render form items -->
<% end_control %>
<!-- add your hidden field here -->
<% 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.



Community Member, 81 Posts

1 October 2010 at 5:56am

I haven't tested this but my first guess would be to create a copy of /sapphire/templates/includes/ 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.


Community Member, 218 Posts

2 October 2010 at 6:28am

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?


Community Member, 218 Posts

2 October 2010 at 6:30am

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


Community Member, 175 Posts

6 October 2010 at 3:31am

Edited: 06/10/2010 3:32am

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


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.


Community Member, 218 Posts

6 October 2010 at 3:33am


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!


Community Member, 218 Posts

6 October 2010 at 4:01am

it worked...but it ALWAYS says services, because im repeating the form on EVERY page, but it originally resides on the "services" 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?

Go to Top