depage-forms v1.4.1
html forms made easy
Loading...
Searching...
No Matches
Stepnav.php
Go to the documentation of this file.
1<?php
2
9
10namespace Depage\HtmlForm\Elements;
11
19{
23 private $htmlString;
24
28 protected $form;
29
36 public function __construct(array $parameters, object $form)
37 {
38 $this->form = $form;
39 }
40
46 public function __toString(): string
47 {
48 $currentStepId = $this->form->getCurrentStepId();
49 $firstInvalidStep = $this->form->getFirstInvalidStep();
50
51 $htmlString = "<ol class=\"stepnav\">";
52 foreach ($this->form->getSteps() as $stepNum => $step) {
53 $link = "";
54 $class = "step-$stepNum";
55 $label = $step->htmlLabel();
56
57 // add link to previously unsaved steps
58 if ($stepNum <= $firstInvalidStep && $stepNum != $currentStepId) {
59 $link = "href=\"" . htmlspecialchars($this->form->buildUrl(['step' => $stepNum])) . "\"";
60 }
61
62 // add valid-class to previous steps
63 if ($stepNum < $currentStepId) {
64 $class .= $step->validate() ? " valid" : " invalid";
65 }
66
67 if ($stepNum == $currentStepId) {
68 $htmlString .= "<li class=\"current-step $class\"><a $link><strong>$label</strong></a></li>";
69 } else {
70 $htmlString .= "<li class=\"$class\"><a $link>$label</a></li>";
71 }
72 }
73 $htmlString .= "</ol>";
74
75 return $htmlString;
76 }
77}
78
79/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Can be used to insert a step navigation.
Definition Stepnav.php:19
__toString()
Renders element to HTML.
Definition Stepnav.php:46
__construct(array $parameters, object $form)
stepnav class constructor
Definition Stepnav.php:36