HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

Add DOB to register PHP file

Hello,

So I have succesfully added additional fields to the registerapproval.php file that I copied and edited for use in a plugin. Similar to the BotStop Plugin. These additional fields are being saved to the database, under their own column under User.

I am struggling with one last element of the registration form however.

I wish to add a Date Of Birth field so that the applicant can insert their DOB. for the Database the date needs to be in YYYY-MM-DD format, but i do not wish to ask someone to type it in this way.

I would like for them to enter it in the DD-MM-YYYY format, then have code convert it to the correct format.

I know this can be done with this PHP code $date = DateTime::createFromFormat('d/m/Y H:i:s', $yourDateString); $dateToBeInserted = $date->format('Y-m-d H:i:s');

But how do I ensure this new variable $dateToBeInserted is added into the database column DateOfBirth?

I know how to add a field in general such as
<li> <?php echo $this->Form->Label('Why do you want to join CV? (Please add any information you think will support your application)', 'DiscoveryText'); echo $this->Form->TextBox('DiscoveryText', array('MultiLine' => TRUE)); ?> </li>

which I copied and modified to
<li> <?php echo $this->Form->Label('How did you find out about The Chaos Vanguard?', 'findOut'); echo $this->Form->TextBox('findOut', array('MultiLine' => TRUE)); ?> </li>

But how do I do this with the date of birth whilst making sure the format is converted correctly?

Comments

  • R_JR_J Ex-Fanboy Munich Moderator

    Instead of adding a text field, you can enter a Date field! (That's what I used in my event calendar.)

    <div class="P EventCalendarInput{$Hidden}">
       {$Sender->Form->Label('Event Date', 'EventCalendarDate')}
       {$Sender->Form->Date('EventCalendarDate', array('YearRange' => '1900-2014', 'fields' => array('day', 'month', 'year')))}
    </div>
    

    With YearRange you can specify which years are allowed for input and array('day', 'month', 'year') specifies the order of the input fields.

    You can enter some validations to the fields of a form:

    public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) {
          $Sender->Validation->ApplyRule('EventCalendarDate', 'Required', T('Please enter an event date'));
          $Sender->Validation->ApplyRule('EventCalendarDate', 'Date', T('The event date you\'ve entered is invalid'));
    

    You might take a look at class form and class validation for more information


    hgtonightOurWebMedia
  • R_JR_J Ex-Fanboy Munich Moderator

    The validation must be inserted before the registration infos are saved. Just look for the right hook in the code


    hgtonight
Sign In or Register to comment.