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, biapar, Willr, Ingo, swaiba, simon_w

Member Profiles - Add subheadings between fields


Reply

5 Posts   728 Views

Avatar
flipsidenz

19 November 2011 at 12:23pm Community Member, 49 Posts

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?

Avatar
danzzz

20 November 2011 at 1:51am Community Member, 175 Posts

you can use LiteralField

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

Avatar
flipsidenz

20 November 2011 at 1:24pm (Last edited: 20 November 2011 1:25pm), Community Member, 49 Posts

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.

Avatar
flipsidenz

27 November 2011 at 7:28am Community Member, 49 Posts

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?

Avatar
borriej

24 January 2012 at 3:13am (Last edited: 24 January 2012 3:13am), Community Member, 267 Posts

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