Repository navigation
Expand file tree
/
Copy pathCheckBoxMenu.php
More file actions
49 lines (38 loc) · 1.39 KB
/
Copy pathCheckBoxMenu.php
File metadata and controls
49 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Example;
class CheckBoxMenu extends \Example\Page
{
public function __construct()
{
parent::__construct();
$this->addBody(new \PHPFUI\Header('CheckBoxMenu Example'));
$this->addBody('Multiple checkboxes as a menu.');
$post = \PHPFUI\Session::getFlash('post');
$posted = $post ? \json_decode($post, true) : [];
$form = new \PHPFUI\Form($this);
$form->setAreYouSure(false);
$form->add($this->getCheckBoxMenu($form, 'selections', ['A', 'B', 'C', 'D', 'F'], $posted['selections'] ?? []));
$form->add(new \PHPFUI\Header('Vertical', 4));
$vertical = $this->getCheckBoxMenu($form, 'options', ['Leather Seats', 'Sunroof', 'Trim', 'Alloy Wheels', 'AWD'], $posted['options'] ?? []);
$vertical->addClass('vertical');
// Example page needs a save field to show post information
$form->add(new \PHPFUI\Input\Hidden('save', 'save'));
$form->add($vertical);
$this->addBody($form);
}
/**
* @param array<string> $options
* @param array<string, string> $posted
*/
private function getCheckBoxMenu(\PHPFUI\Form $form, string $name, array $options, array $posted) : \PHPFUI\Input\CheckBoxMenu
{
$checkBoxMenu = new \PHPFUI\Input\CheckBoxMenu($name);
$checkBoxMenu->addAll();
foreach ($options as $index => $item)
{
$checkBoxMenu->addCheckBox($item, isset($posted[$index]), $item);
}
$checkBoxMenu->addSubmit($form, 'Apply');
return $checkBoxMenu;
}
}