silverstripe-framework/tests/php/Forms/EmailFieldTest/TestController.php

74 lines
1.6 KiB
PHP
Raw Normal View History

2016-10-14 03:30:05 +02:00
<?php
namespace SilverStripe\Forms\Tests\EmailFieldTest;
use SilverStripe\Control\Controller;
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;
/**
* @skipUpgrade
*/
class TestController extends Controller implements TestOnly
{
private static $allowed_actions = array('Form');
2016-10-14 03:30:05 +02:00
private static $url_handlers = array(
'$Action//$ID/$OtherID' => "handleAction",
);
2016-10-14 03:30:05 +02:00
protected $template = 'BlankPage';
2016-10-14 03:30:05 +02:00
function Link($action = null)
{
/**
* @skipUpgrade
*/
return Controller::join_links(
'EmailFieldTest_Controller',
$this->getRequest()->latestParam('Action'),
$this->getRequest()->latestParam('ID'),
$action
);
}
2016-10-14 03:30:05 +02:00
function Form()
{
$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
// Disable CSRF protection for easier form submission handling
$form->disableSecurityToken();
2016-10-14 03:30:05 +02:00
return $form;
}
2016-10-14 03:30:05 +02:00
function doSubmit($data, $form, $request)
{
$form->sessionMessage('Test save was successful', 'good');
return $this->redirectBack();
}
2016-10-14 03:30:05 +02:00
function getViewer($action = null)
{
return new SSViewer('BlankPage');
}
2016-10-14 03:30:05 +02:00
}