-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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