Skip to content

Instantly share code, notes, and snippets.

@pepebe
Forked from jonleverrier/getFormSteps.snippet.php
Created December 5, 2018 15:11
Show Gist options
  • Save pepebe/343312aa7b30979cb0aa874580e4d200 to your computer and use it in GitHub Desktop.
Save pepebe/343312aa7b30979cb0aa874580e4d200 to your computer and use it in GitHub Desktop.
getFormSteps for the MODX Formalicious form builder by Sterc. This utility snippet displays all the step titles for a given form ID.
<?php
/*
getFormSteps snippet
for the Formalicious form builder for MODX by Sterc
This utility snippet displays all the step titles for a given form ID
Put the snippet in the Formalcious steps tpl and call like this;
[[!getFormSteps? stepFormId=`[[!+form_id]]` &tpl=`myFormStepsTpl`]]
Available placeholders in the snippet tpl are;
[[+title]] // which displays the title of the step
[[+rank]] // displays the order of the steps starting from 0
v.0.0.1a
by Jon Leverrier
*/
// receive id of the form from the snippet call
$stepFormId = $modx->getOption('stepFormId', $scriptProperties);
// if there is no form id, stop here...
if (empty($stepsFormId)) {
return;
} else {
// get related steps based on form_id
$output = array();
$getFormSteps = $modx->query("SELECT * FROM `modx_formalicious_steps` WHERE `form_id` ='" . $stepsFormId . "'");
if ($getFormSteps) {
while ($row = $getFormSteps->fetch(PDO::FETCH_ASSOC)) {
$placeholders = array_merge($scriptProperties, $row);
if (!empty($tpl)) {
// if a tpl is defined in the snippet call, get placeholders
$output[] = $modx->getChunk($tpl, $placeholders);
} else {
// if no tpl defined in the snippet call, output an array
$output[] = "<pre>" . print_r($placeholders, true) . "</pre>";
}
}
}
return implode("\n", $output);
}
<?php
/*
getFormStepsActive snippet
for the Formalicious form builder for MODX by Sterc
A utility snippet that works with getFormSteps snippet
*** To be used in the tpl of getFormSteps ***
This snippet sets some placeholders so that it can be
used to assign an active or completed class to the current
or passed form step(s).
Use like this:
[[!getFormStepsActive? &rank=`[[!+rank:add=`1`]]`]]
Sets the active class:
[[+rank:eq=`[[+step]]`:then=`c-stepprocess__item--active`:else=``]]
Sets a complete class:
[[+rank:lt=`[[+step]]`:then=`c-stepprocess__item--complete`:else=``]]
*/
if (empty($rank)) {
return;
} else {
//$param = $modx->getPlaceholder('stepParam');
// the below line presumes that your stepParam is set to
// "p" in the renderForm snippet. If not change it here...
$step = $modx->getOption('p', $_GET, 1);
$rank = $modx->getOption('rank', $scriptProperties);
// set placeholders...
$modx->setPlaceholder('rank', $rank);
$modx->setPlaceholder('step', $step);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment