Test Failed
Push — master ( 194522...eda1b6 )
by Mikael
01:43
created

FormModel::callbackSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
/**
6
 * Base class for form model classes.
7
 *
8
 */
9
abstract class FormModel extends Form
10
{
11
    /**
12
     * Customise the check() method to use own methods.
13
     *
14
     * @param callable $callIfSuccess handler to call if function returns true.
15
     * @param callable $callIfFail    handler to call if function returns true.
16
     */
17
    public function check($callIfSuccess = null, $callIfFail = null)
18
    {
19
        return parent::check([$this, "callbackSuccess"], [$this, "callbackFail"]);
20
    }
21
22
23
24
    /**
25
     * Callback for submitting the form.
26
     */
27
    abstract public function callbackSubmit();
28
29
30
31
    /**
32
     * Callback What to do if the form was submitted successfully?
33
     */
34
    public function callbackSuccess()
35
    {
36
        $this->AddOUtput("<p>#callbackSuccess()</p>");
37
        $this->AddOUtput("<p>Form was submitted and the callback method returned true.</p>");
38
        header("Location: " . $_SERVER['PHP_SELF']);
39
    }
40
41
42
43
    /**
44
     * Callback What to do when submitted form could not be processed?
45
     */
46
    public function callbackFail()
47
    {
48
        $this->AddOutput("<p>#callbackFailed()</p>");
49
        $this->AddOutput("<p>Form was submitted and the Check() method returned false.</p>");
50
        header("Location: " . $_SERVER['PHP_SELF']);
51
    }
52
}
53