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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Frontend form fields


Reply


5 Posts   1364 Views

Avatar
Tee808

Community Member, 6 Posts

10 July 2011 at 10:26pm

Edited: 10/07/2011 10:40pm

I am using the memberprofile module. To add a date field for Date of Birth and a Gender dropdown, I have extended the Members class by doing the following:

class Customregfields extends DataObjectDecorator{
   function extraStatics(){
      return array(
         'db' => array(
       'Gender' => "Enum(',Male,Female','')",
'DOB' => "Date"
      );
   }
}

What do I need to do to achieve the following?
1. Have the Date of Birth field display in the frontend registration form as three dropdowns Day, Month, Year.
2. Change the Gender dropdown to radio buttons.

Avatar
swaiba

Forum Moderator, 1799 Posts

11 July 2011 at 8:23pm

Hi Tee808,

This should work for (1), but I don't have an answer for (2)... hope it helps!

function getCMSFields() {
   $fields = parent::getCMSFields();
   $df = new DateField('DOB','Date Of Birth');
   $df->setConfig('showcalendar', true);
   $df->setLocale('en_GB');
   $df->setConfig('dateformat', 'dd/MM/YYYY');

   $fields-replaceField('DOB',$df);
   return $fields;
}

Note I am in the UK, so I use UK date format and I believe the (very confusing to me) US format is the default so you shouldn't need the last two lines...

Avatar
Tee808

Community Member, 6 Posts

11 July 2011 at 10:45pm

Thanks for your reply. I'm not sure you understood what I am needing though.

I'm wanting three dropdowns: day, month and year.

Avatar
swaiba

Forum Moderator, 1799 Posts

11 July 2011 at 10:52pm

ah, my bad, totally doesn't do that, it can provide three boxes - but I wrote a massive amount of custom code to do three dropdowns - not something that can be summed up in three lines... sorry for the confusion...

Avatar
swaiba

Forum Moderator, 1799 Posts

5 December 2011 at 4:11am

I have just gone back to revaluate my code and found this...

https://github.com/sunnysideup/silverstripe-form-fields

...thought I'd update the thread