Completed
Push — master ( ed2b3e...68d467 )
by Mikael
02:34
created

FormModelValidateMail   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 29 1
A callbackSubmit() 0 9 1
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
use Anax\DI\DIInterface;
6
7
/**
8
 * Example of FormModel implementation.
9
 */
10
class FormModelValidateMail extends FormModel
11
{
12
    /**
13
     * Constructor injects with DI container.
14
     *
15
     * @param Anax\DI\DIInterface $di a service container
16
     */
17
    public function __construct(DIInterface $di)
18
    {
19
        parent::__construct($di);
20
        $this->form->create(
21
            [
22
                "id" => __CLASS__,
23
                "legend" => "Legend",
24
            ],
25
            [
26
                "mail1" => [
27
                    "type" =>"text",
28
                    "label" => "Email (as input type=text)",
29
                    "validation" => ["email"],
30
                ],
31
32
                "mail2" => [
33
                    "type" =>"email",
34
                    "label" => "Email (as input type=email)",
35
                    "validation" => ["email"],
36
                ],
37
38
                "submit" => [
39
                    "type" => "submit",
40
                    "value" => "Submit",
41
                    "callback" => [$this, "callbackSubmit"]
42
                ],
43
            ]
44
        );
45
    }
46
47
48
49
    /**
50
     * Callback for submit-button which should return true if it could
51
     * carry out its work and false if something failed.
52
     *
53
     * @return boolean true if okey, false if something went wrong.
54
     */
55
    public function callbackSubmit()
56
    {
57
        $this->form->addOutput("Validation passes.");
58
59
        // Remember values during resubmit, for sake of the example
60
        $this->form->rememberValues();
61
62
        return true;
63
    }
64
}
65