Code Duplication    Length = 49-61 lines in 2 locations

src/HTMLForm/FormModelLogin.php 1 location

@@ 10-70 (lines=61) @@
7
/**
8
 * Example of FormModel implementation.
9
 */
10
class FormModelLogin 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
21
        $this->form->create(
22
            [
23
                "id" => __CLASS__,
24
                "legend" => "User Login"
25
            ],
26
            [
27
                "user" => [
28
                    "type"        => "text",
29
                    //"description" => "Here you can place a description.",
30
                    //"placeholder" => "Here is a placeholder",
31
                ],
32
                        
33
                "password" => [
34
                    "type"        => "password",
35
                    //"description" => "Here you can place a description.",
36
                    //"placeholder" => "Here is a placeholder",
37
                ],
38
39
                "submit" => [
40
                    "type" => "submit",
41
                    "value" => "Login",
42
                    "callback" => [$this, "callbackSubmit"]
43
                ],
44
            ]
45
        );
46
    }
47
48
49
50
    /**
51
     * Callback for submit-button which should return true if it could
52
     * carry out its work and false if something failed.
53
     *
54
     * @return boolean true if okey, false if something went wrong.
55
     */
56
    public function callbackSubmit()
57
    {
58
        $this->form->addOutput(
59
            "Trying to login as: "
60
            . $this->form->value("user")
61
            . "<br>Password is kept a secret..."
62
            //. $this->form->value("password")
63
        );
64
65
        // Remember values during resubmit
66
        $this->form->rememberValues();
67
68
        return true;
69
    }
70
}
71

src/HTMLForm/FormModelValidateNotEmpty.php 1 location

@@ 10-58 (lines=49) @@
7
/**
8
 * Example of FormModel implementation.
9
 */
10
class FormModelValidateNotEmpty 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
                "text" => [
27
                    "type" =>"text",
28
                    "label" => "Text, not empty (as input type=text)",
29
                    "validation" => ["not_empty"],
30
                ],
31
32
                "submit" => [
33
                    "type" => "submit",
34
                    "value" => "Submit",
35
                    "callback" => [$this, "callbackSubmit"]
36
                ],
37
            ]
38
        );
39
    }
40
41
42
43
    /**
44
     * Callback for submit-button which should return true if it could
45
     * carry out its work and false if something failed.
46
     *
47
     * @return boolean true if okey, false if something went wrong.
48
     */
49
    public function callbackSubmit()
50
    {
51
        $this->form->addOutput("Validation passes.");
52
53
        // Remember values during resubmit, for sake of the example
54
        $this->form->rememberValues();
55
56
        return true;
57
    }
58
}
59