depage-forms
v2.0.0
html forms made easy
Toggle main menu visibility
Loading...
Searching...
No Matches
Stepnav.php
Go to the documentation of this file.
1
<?php
2
9
10
namespace
Depage\HtmlForm\Elements;
11
18
class
Stepnav
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 : */
Depage\HtmlForm\Elements\Stepnav
Can be used to insert a step navigation.
Definition
Stepnav.php:19
Depage\HtmlForm\Elements\Stepnav\$form
$form
form object
Definition
Stepnav.php:28
Depage\HtmlForm\Elements\Stepnav\__toString
__toString()
Renders element to HTML.
Definition
Stepnav.php:46
Depage\HtmlForm\Elements\Stepnav\__construct
__construct(array $parameters, object $form)
stepnav class constructor
Definition
Stepnav.php:36
Elements
Stepnav.php
Generated on
for depage-forms by
doxygen
1.18.0
For an overview of all docs, go to
docs.depage.net