Skip to content

Instantly share code, notes, and snippets.

@maxime-rainville
Created May 8, 2018 06:26
Show Gist options
  • Save maxime-rainville/b883fe6132d298a3c74443632ff608d3 to your computer and use it in GitHub Desktop.
Save maxime-rainville/b883fe6132d298a3c74443632ff608d3 to your computer and use it in GitHub Desktop.
<?php
namespace {
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
class PageController extends ContentController
{
/**
* An array of actions that can be accessed via a request. Each array element should be an action name, and the
* permissions or conditions required to allow the user to access it.
*
* <code>
* [
* 'action', // anyone can access this action
* 'action' => true, // same as above
* 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
* 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
* ];
* </code>
*
* @var array
*/
private static $allowed_actions = ['Form'];
protected function init()
{
parent::init();
// You can include any CSS or JS required by your project here.
// See: https://docs.silverstripe.org/en/developer_guides/templates/requirements/
}
public function Form()
{
$dateField = DateField::create('birthdate', 'Your Birthdate')
->setMaxDate('-21 years')
->setHTML5(false)
// ->setDateFormat('MM/dd/yyyy')
->setValue('2018-05-08');
return new Form(
$this,
'Form',
new FieldList([$dateField]),
new FieldList([FormAction::create('test', 'Test')])
);
}
public function test($data, $form)
{
var_dump($data);
die('test');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment