Completed
Push — 4.2.0 ( f03d5e...24bd0a )
by Daniel
12:22 queued 05:26
created

doSubmit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
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');
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
35
36
    private static $url_handlers = array(
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

85
    public function doSubmit($data, $form, /** @scrutinizer ignore-unused */ $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

85
    public function doSubmit(/** @scrutinizer ignore-unused */ $data, $form, $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
    {
87
        $form->sessionMessage('Test save was successful', 'good');
88
        return $this->redirectBack();
89
    }
90
91
    public function doTriggerException($data, $form, $request)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

91
    public function doTriggerException(/** @scrutinizer ignore-unused */ $data, $form, $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $form is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

91
    public function doTriggerException($data, /** @scrutinizer ignore-unused */ $form, $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

91
    public function doTriggerException($data, $form, /** @scrutinizer ignore-unused */ $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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