1 | <?php |
||
12 | class UpdateForm extends FormModel |
||
13 | { |
||
14 | /** |
||
15 | * Constructor injects with DI container and the id to update. |
||
16 | * |
||
17 | * @param Anax\DI\DIInterface $di a service container |
||
18 | * @param integer $id to update |
||
19 | */ |
||
20 | 1 | public function __construct(DIInterface $di, $id) |
|
21 | { |
||
22 | 1 | parent::__construct($di); |
|
23 | 1 | $comment = $this->getItemDetails($id); |
|
24 | 1 | $this->form->create( |
|
25 | [ |
||
26 | 1 | "id" => __CLASS__, |
|
27 | // "legend" => "Update details of the item", |
||
28 | ], |
||
29 | [ |
||
30 | 1 | "id" => [ |
|
31 | 1 | "type" => "text", |
|
32 | "validation" => ["not_empty"], |
||
33 | "readonly" => true, |
||
34 | 1 | "value" => $comment->id, |
|
35 | ], |
||
36 | |||
37 | "email" => [ |
||
38 | 1 | "type" => "text", |
|
39 | 1 | "label" => "E-mail:", |
|
40 | "validation" => ["not_empty"], |
||
41 | 1 | "value" => $comment->email, |
|
42 | ], |
||
43 | |||
44 | "text" => [ |
||
45 | 1 | "type" => "textarea", |
|
46 | 1 | "label" => "Comment:", |
|
47 | "validation" => ["not_empty"], |
||
48 | 1 | "value" => $comment->text, |
|
49 | ], |
||
50 | |||
51 | "submit" => [ |
||
52 | 1 | "type" => "submit", |
|
53 | 1 | "value" => "Save", |
|
54 | 1 | "callback" => [$this, "callbackSubmit"] |
|
55 | ], |
||
56 | |||
57 | "reset" => [ |
||
58 | "type" => "reset", |
||
59 | "value" => "Reset" |
||
60 | ], |
||
61 | ] |
||
62 | ); |
||
63 | 1 | } |
|
64 | |||
65 | |||
66 | |||
67 | /** |
||
68 | * Get details on item to load form with. |
||
69 | * |
||
70 | * @param integer $id get details on item with id. |
||
71 | * |
||
72 | * @return Comment |
||
73 | */ |
||
74 | 1 | public function getItemDetails($id) |
|
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * Callback for submit-button which should return true if it could |
||
86 | * carry out its work and false if something failed. |
||
87 | * |
||
88 | * @return boolean true if okey, false if something went wrong. |
||
89 | */ |
||
90 | public function callbackSubmit() |
||
100 | } |
||
101 |