1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Forms\Tests\FormTest; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
6
|
|
|
use SilverStripe\Dev\TestOnly; |
7
|
|
|
use SilverStripe\Forms\CheckboxSetField; |
8
|
|
|
use SilverStripe\Forms\DateField; |
9
|
|
|
use SilverStripe\Forms\EmailField; |
10
|
|
|
use SilverStripe\Forms\FieldList; |
11
|
|
|
use SilverStripe\Forms\Form; |
12
|
|
|
use SilverStripe\Forms\FormAction; |
13
|
|
|
use SilverStripe\Forms\MoneyField; |
14
|
|
|
use SilverStripe\Forms\NumericField; |
15
|
|
|
use SilverStripe\Forms\RequiredFields; |
16
|
|
|
use SilverStripe\Forms\TextField; |
17
|
|
|
use SilverStripe\ORM\ValidationException; |
18
|
|
|
use SilverStripe\ORM\ValidationResult; |
19
|
|
|
use SilverStripe\View\SSViewer; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @skipUpgrade |
23
|
|
|
*/ |
24
|
|
|
class ControllerWithSpecialSubmittedValueFields extends Controller implements TestOnly |
25
|
|
|
{ |
26
|
|
|
public function __construct() |
27
|
|
|
{ |
28
|
|
|
parent::__construct(); |
29
|
|
|
if (Controller::has_curr()) { |
30
|
|
|
$this->setRequest(Controller::curr()->getRequest()); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
private static $allowed_actions = array('Form'); |
|
|
|
|
35
|
|
|
|
36
|
|
|
private static $url_handlers = array( |
|
|
|
|
37
|
|
|
'$Action//$ID/$OtherID' => "handleAction", |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
protected $template = 'BlankPage'; |
41
|
|
|
|
42
|
|
|
public function Link($action = null) |
43
|
|
|
{ |
44
|
|
|
return Controller::join_links( |
45
|
|
|
'FormTest_ControllerWithSpecialSubmittedValueFields', |
46
|
|
|
$this->getRequest()->latestParam('Action'), |
47
|
|
|
$this->getRequest()->latestParam('ID'), |
48
|
|
|
$action |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function Form() |
53
|
|
|
{ |
54
|
|
|
$form = new Form( |
55
|
|
|
$this, |
56
|
|
|
'Form', |
57
|
|
|
new FieldList( |
58
|
|
|
new TextField('SomeRequiredField'), |
59
|
|
|
DateField::create('SomeDateField') |
60
|
|
|
->setHTML5(false) |
61
|
|
|
->setDateFormat('dd/MM/yyyy') |
62
|
|
|
->setValue('2000-01-01'), |
63
|
|
|
NumericField::create('SomeFrenchNumericField') |
64
|
|
|
->setHTML5(false) |
65
|
|
|
->setLocale('fr_FR') |
66
|
|
|
->setScale(4) |
67
|
|
|
->setValue(12345.6789), |
68
|
|
|
MoneyField::create('SomeFrenchMoneyField') |
69
|
|
|
->setValue('100.5 EUR') |
70
|
|
|
->setLocale('fr_FR') |
71
|
|
|
), |
72
|
|
|
new FieldList( |
73
|
|
|
FormAction::create('doSubmit') |
74
|
|
|
), |
75
|
|
|
new RequiredFields( |
76
|
|
|
'SomeRequiredField' |
77
|
|
|
) |
78
|
|
|
); |
79
|
|
|
$form->setValidationExemptActions(array('doSubmitValidationExempt')); |
80
|
|
|
$form->disableSecurityToken(); // Disable CSRF protection for easier form submission handling |
81
|
|
|
|
82
|
|
|
return $form; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function doSubmit($data, $form, $request) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$form->sessionMessage('Test save was successful', 'good'); |
88
|
|
|
return $this->redirectBack(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function doTriggerException($data, $form, $request) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$result = new ValidationResult(); |
94
|
|
|
$result->addFieldError('Email', 'Error on Email field'); |
95
|
|
|
$result->addError('Error at top of form'); |
96
|
|
|
throw new ValidationException($result); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getViewer($action = null) |
100
|
|
|
{ |
101
|
|
|
return new SSViewer('BlankPage'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|