SearchForm::callbackSubmit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
namespace Alfs18\User\HTMLForm;
4
5
use Anax\HTMLForm\FormModel;
6
use Psr\Container\ContainerInterface;
7
8
/**
9
 * Example of FormModel implementation.
10
 */
11
class SearchForm extends FormModel
12
{
13
    /**
14
     * Constructor injects with DI container.
15
     *
16
     * @param Anax\DI\DIInterface $di a service container
0 ignored issues
show
Bug introduced by
The type Alfs18\User\HTMLForm\Anax\DI\DIInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
     */
18
    public function __construct(ContainerInterface $di)
19
    {
20
        parent::__construct($di);
21
        $this->form->create(
22
            [
23
                "id" => __CLASS__,
24
                // "legend" => "Legend",
25
                //"wrapper-element" => "div",
26
            ],
27
            [
28
                "search" => [
29
                    "type"        => "search-widget",
30
                    // "description" => "Here you can place a description.",
31
                    "placeholder" => "Sök",
32
                    "label"       => "Sök",
33
                    "callback"    => [$this, "callbackSubmit"],
34
                ]
35
            ]
36
        );
37
    }
38
39
40
41
    /**
42
     * Callback for submit-button which should return true if it could
43
     * carry out its work and false if something failed.
44
     *
45
     * @return boolean true if okey, false if something went wrong.
46
     */
47
    public function callbackSubmit()
48
    {
49
        $this->form->addOutput(
50
            "Searchstring is: "
51
            . $this->form->value("search")
52
            . "</br>"
53
        );
54
55
        // Remember values during resubmit, for sake of the example
56
        $this->form->rememberValues();
57
58
        return true;
59
    }
60
}
61