Jump to:

23452 Posts in 18901 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Frontend form fields

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

Page: 1
Go to End
Author Topic: 1312 Views
  • Tee808
    Avatar
    Community Member
    6 Posts

    Frontend form fields Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Frontend form fields Link to this post

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

  • Tee808
    Avatar
    Community Member
    6 Posts

    Re: Frontend form fields Link to this post

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

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

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Frontend form fields Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Frontend form fields Link to this post

    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

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