Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Member Profiles - Add subheadings between fields

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 692 Views
  • flipsidenz
    Avatar
    Community Member
    49 Posts

    Member Profiles - Add subheadings between fields Link to this post

    I'm using the member profile module to make a login area to my website.

    The registration process now has many fields, which needs splitting up into sub headings.

    How do you go about inserting sub headings at certain points in the profile form?

    Can anyone help?

  • danzzz
    Avatar
    Community Member
    175 Posts

    Re: Member Profiles - Add subheadings between fields Link to this post

    you can use LiteralField

    New LiteralField('HeadingAdressSection', '<h3>Please give us your adress</h3>')

  • flipsidenz
    Avatar
    Community Member
    49 Posts

    Re: Member Profiles - Add subheadings between fields Link to this post

    Thanks for taking the time out to reply.

    I'm familiar with literal field. However, are you aware of the member profiles module and how it works? If only it were that easy...

    Here's where I am so far. I have installed the member profiles module, created a MemberDecorator as a Dataobject decorator.

    In the decorator, I have added some custom stats like so:

    function extraStatics() {
          return array (
          'db' => array(
                'Role' => 'Varchar(255)',
                'Organization' => 'Varchar(255)',
                'Secondary Email' => 'Varchar(255)',
              'PhoneNumber' => 'Varchar(255)',
                'HomePhone' => 'Varchar(255)',
                'FaxNumber' => 'Varchar(255)',
                'Mobile' => 'Varchar(255)',
                'PreferredContactMethod' => "Enum('Email,Fax,txt','Email')",
                'PreferredEmergencyContactMethod' => "Enum('Email,Fax,txt','Email')",
                'WorkAddress' => 'Varchar(255)',
                'City' => 'Varchar(255)',
                'PostalCode' => 'Varchar(255)',
                'Status' => "Enum('txt','txt')",
                'HeadingAdressSection' => 'Varchar(255)'
             ),
             'defaults' => array(
              'Status' => 'Disabled'
             )
             //,'has_many' => array( 'Subscription' => 'Subscription' )
             );
       }

    If you see, the last database entry is "HeadingAddressSection" so what I need to do is have member profiles recognise this as a literal field, so I have set the following:

    public function updateMemberFormFields(&$fields) {
          $fields->removeByName('HeadingAdressSection');
          $fields->push( new LiteralField('HeadingAdressSection', '<h3>Please give us your adress</h3>'));   
       }

    Attempting to remove the field which member profile creates, and adding my new literal field.

    This, however doesn't work. It stops that field from being added to the member profile list of fields entirely.

    Does this make sense now?

    If anyone can provide help, I'd really appreciate it.

  • flipsidenz
    Avatar
    Community Member
    49 Posts

    Re: Member Profiles - Add subheadings between fields Link to this post

    I've ended up adding LiteralFields into the MemberProfilePage.php decorator under "getProfileFields".

    $fields->insertBefore(new LiteralField (
                'MemberHeader', '<h2>Heading</h2><p>blah blah blah.</p>')
             , 'Role');

    Not ideal, as this depends on the field "Role" being active on the registration form. But at least it gets the content into the form at the appropriate spot.

    Still happy to hear more appropriate alternatives?

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Member Profiles - Add subheadings between fields Link to this post

    do this:

    <?php

    class MemberProfilePage_ControllerDecorator extends DataObjectDecorator {

    public function updateProfileFields(&$fields) {
          $fields->insertBefore(new LiteralField('Hd_Personal', '<h3>Personal data<h3>'), 'FirstName');
    }
       
    }

    and to config add

    Object::add_extension('MemberProfilePage_Controller', 'MemberProfilePage_ControllerDecorator');

    all credits for Zauberfisch

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