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.

All other Modules /

Discuss all other Modules here.

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

Adding a LiteralField to Member-Profile module


Go to End


4 Posts   1063 Views

Avatar
Babalou

Community Member, 21 Posts

30 June 2015 at 4:08am

So I have been hunting around for the answer to this for some time.
I can add fields to the registration page using the Member Profiles module by following these instructions
http://www.silverstripe.org/community/forums/all-other-modules/show/22082
Which were very helpful.
The problem is I need to add LiteralFields to to the layout and this method does not appear to support that.
The field simply doesn't show up when added to the $fields list.
$fields->push(new LiteralField('Name', 'Content');
No error is generated that I can see and no other oddities occur. The field is simply ignored.
Any idea what I am supposed to do here?

Avatar
Pyromanik

Community Member, 419 Posts

5 July 2015 at 9:08pm

Edited: 05/07/2015 9:09pm

'Content' is e.g. '<div><h1>Some Content</h1></div>' yeah?
Inspect the html output and see if it shows. Could be some CSS hiding it.
Otherwise try using a different 'Name' - a field added later with the same name will overwrite it.

Avatar
Babalou

Community Member, 21 Posts

6 July 2015 at 3:35am

Thanks for that.
It's nice to know that I am not crazy and at least one other person thinks that this should just work.
Will look into your suggestions and get back.

Avatar
Babalou

Community Member, 21 Posts

29 July 2015 at 3:32am

Edited: 29/07/2015 3:35am

So the way I resolved this is probably not the ideal way but it does have the advantage that it works.
For whatever reason I am unable to add LiteralFields to the Member Profiles registration form using the method linked in this thread.
But since the module extends Page I was able to interfere with it after the form was created by overriding two templates and introducing a function into Page.php.

First - Override 'MemberProfilePage_register.ss' and in place of $form I placed my own function name $Top.RegistrationForm.
Second - Create new template RegisterForm.ss and copy the code from /framework/templates/includes/Form.ss -- You don't have to do this but since we are customising we might as well get all the controls into our hands
Third - in Page.php create the function RegistrationForm

	public function RegistrationForm(){
		// grab the form
		$alteredRegForm = $this->RegisterForm();
		// add the new form template
		$alteredRegForm->setTemplate('RegisterForm');
		// remove an unwanted field
		$alteredRegForm->fields->removeByName('VisibilityNote');
		// add a wanted field
		$termsfield = new LiteralField("Terms", "Some Text here");
		$alteredRegForm->fields->insertBefore($termsfield, 'SomeOtherField');
		return $alteredRegForm;
	}

That'll do it. Now you have everything you need to customise the registration form in Member Profiles