stepnav.php
Go to the documentation of this file.
1 <?php
9 namespace depage\htmlform\elements;
10 
17 class stepnav
18 {
22  private $htmlString;
23 
31  public function __construct($parameters, $form)
32  {
33  $this->form = $form;
34  }
35 
41  public function __toString()
42  {
43  $currentStepId = $this->form->getCurrentStepId();
44  $firstInvalidStep = $this->form->getFirstInvalidStep();
45 
46  $htmlString = "<ol class=\"stepnav\">";
47  foreach ($this->form->getSteps() as $stepNum => $step) {
48  $link = "";
49  $class = "step-$stepNum";
50  $label = $step->htmlLabel();
51 
52  // add link to previously unsaved steps
53  if ($stepNum <= $firstInvalidStep && $stepNum != $currentStepId) {
54  $link = "href=\"{$this->form->url['path']}" . htmlspecialchars($this->form->buildUrlQuery(array('step' => $stepNum))) . "\"";
55  }
56 
57  // add valid-class to previous steps
58  if ($stepNum < $currentStepId) {
59  $class .= $step->validate() ? " valid" : " invalid";
60  }
61 
62  if ($stepNum == $currentStepId) {
63  $htmlString .= "<li class=\"current-step $class\"><a $link><strong>$label</strong></a></li>";
64  } else {
65  $htmlString .= "<li class=\"$class\"><a $link>$label</a></li>";
66  }
67  }
68  $htmlString .= "</ol>";
69 
70  return $htmlString;
71  }
72 }
73 
74 /* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Can be used to insert a step navigation.
Definition: stepnav.php:17
__construct($parameters, $form)
stepnav class constructor
Definition: stepnav.php:31
__toString()
Renders element to HTML.
Definition: stepnav.php:41