|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Firesphere\PartialUserforms\Forms; |
|
4
|
|
|
|
|
5
|
|
|
use Firesphere\PartialUserforms\Controllers\PartialUserFormVerifyController; |
|
6
|
|
|
use SilverStripe\Forms\FieldList; |
|
7
|
|
|
use SilverStripe\Forms\Form; |
|
8
|
|
|
use SilverStripe\Forms\FormAction; |
|
9
|
|
|
use SilverStripe\Forms\PasswordField; |
|
10
|
|
|
use SilverStripe\Forms\RequiredFields; |
|
11
|
|
|
use SilverStripe\Forms\Validator; |
|
12
|
|
|
|
|
13
|
|
|
class PasswordForm extends Form |
|
14
|
|
|
{ |
|
15
|
|
|
public const PASSWORD_SESSION_KEY = 'PartialFormSession'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* PasswordForm constructor. |
|
19
|
|
|
* @param PartialUserFormVerifyController|null $controller |
|
20
|
|
|
* @param string $name |
|
21
|
|
|
* @param FieldList|null $fields |
|
22
|
|
|
* @param FieldList|null $actions |
|
23
|
|
|
* @param Validator|null $validator |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct( |
|
26
|
|
|
PartialUserFormVerifyController $controller = null, |
|
27
|
|
|
$name = self::DEFAULT_NAME, |
|
28
|
|
|
FieldList $fields = null, |
|
29
|
|
|
FieldList $actions = null, |
|
30
|
|
|
Validator $validator = null |
|
31
|
|
|
) { |
|
32
|
|
|
if (!$fields) { |
|
33
|
|
|
$fields = $this->getFields(); |
|
34
|
|
|
} |
|
35
|
|
|
if (!$actions) { |
|
36
|
|
|
$actions = $this->getActions(); |
|
37
|
|
|
} |
|
38
|
|
|
if (!$validator) { |
|
39
|
|
|
$validator = $this->getFormValidator(); |
|
40
|
|
|
} |
|
41
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator); |
|
42
|
|
|
|
|
43
|
|
|
$this->setFormAction(sprintf('/verify/%s', $name)); |
|
44
|
|
|
|
|
45
|
|
|
// Add the userform class to the form, so it's can be styled similar to the actual userforms more easily |
|
46
|
|
|
$this->addExtraClass('userform'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return FieldList |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function getFields() |
|
53
|
|
|
{ |
|
54
|
|
|
return FieldList::create([ |
|
55
|
|
|
PasswordField::create('Password', _t(__CLASS__ . '.PasswordField', 'Password')) |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return FieldList |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function getActions() |
|
63
|
|
|
{ |
|
64
|
|
|
return FieldList::create([ |
|
65
|
|
|
FormAction::create('doValidate', _t(__CLASS__ . '.Validate', 'Submit')) |
|
66
|
|
|
]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return RequiredFields |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getFormValidator() |
|
73
|
|
|
{ |
|
74
|
|
|
return RequiredFields::create(['Password']); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|