2016-10-14 03:30:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests\EmailFieldTest;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Controller;
|
2017-06-22 12:50:45 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2016-10-14 03:30:05 +02:00
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
use SilverStripe\Forms\EmailField;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\Forms\FormAction;
|
|
|
|
use SilverStripe\Forms\RequiredFields;
|
|
|
|
use SilverStripe\View\SSViewer;
|
|
|
|
|
|
|
|
class TestController extends Controller implements TestOnly
|
|
|
|
{
|
2017-06-22 12:50:45 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
if (Controller::has_curr()) {
|
|
|
|
$this->setRequest(Controller::curr()->getRequest());
|
|
|
|
}
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $allowed_actions = ['Form'];
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $url_handlers = [
|
2016-12-16 05:34:21 +01:00
|
|
|
'$Action//$ID/$OtherID' => "handleAction",
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $template = 'BlankPage';
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
public function Link($action = null)
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
return Controller::join_links(
|
|
|
|
'EmailFieldTest_Controller',
|
|
|
|
$this->getRequest()->latestParam('Action'),
|
|
|
|
$this->getRequest()->latestParam('ID'),
|
|
|
|
$action
|
|
|
|
);
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
/**
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function Form()
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
$form = new Form(
|
|
|
|
$this,
|
|
|
|
'Form',
|
|
|
|
new FieldList(
|
|
|
|
new EmailField('Email')
|
|
|
|
),
|
|
|
|
new FieldList(
|
|
|
|
new FormAction('doSubmit')
|
|
|
|
),
|
|
|
|
new RequiredFields(
|
|
|
|
'Email'
|
|
|
|
)
|
|
|
|
);
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
// Disable CSRF protection for easier form submission handling
|
|
|
|
$form->disableSecurityToken();
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
return $form;
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
public function doSubmit($data, Form $form, HTTPRequest $request)
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
$form->sessionMessage('Test save was successful', 'good');
|
|
|
|
return $this->redirectBack();
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
public function getViewer($action = null)
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
return new SSViewer('BlankPage');
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
}
|