2016-10-14 03:30:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests\FormTest;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Controller;
|
2022-10-17 06:58:20 +02:00
|
|
|
use SilverStripe\Control\HTTPResponse;
|
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;
|
|
|
|
|
|
|
|
class ControllerWithStrictPostCheck extends Controller implements TestOnly
|
|
|
|
{
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $allowed_actions = ['Form'];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
protected $template = 'BlankPage';
|
|
|
|
|
|
|
|
public function Link($action = null)
|
|
|
|
{
|
|
|
|
return Controller::join_links(
|
|
|
|
'FormTest_ControllerWithStrictPostCheck',
|
|
|
|
$this->request->latestParam('Action'),
|
|
|
|
$this->request->latestParam('ID'),
|
|
|
|
$action
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Form()
|
|
|
|
{
|
|
|
|
$form = new Form(
|
|
|
|
$this,
|
|
|
|
'Form',
|
|
|
|
new FieldList(
|
|
|
|
new EmailField('Email')
|
|
|
|
),
|
|
|
|
new FieldList(
|
|
|
|
new FormAction('doSubmit')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$form->setFormMethod('POST');
|
|
|
|
$form->setStrictFormMethodCheck(true);
|
|
|
|
$form->disableSecurityToken(); // Disable CSRF protection for easier form submission handling
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:58:20 +02:00
|
|
|
public function doSubmit(array $data, Form $form): HTTPResponse
|
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
|
|
|
}
|