Skip to content

Instantly share code, notes, and snippets.

@jonleverrier
Last active December 12, 2018 17:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonleverrier/0da9345f6b4eb1e2be881891ae3e9a2b to your computer and use it in GitHub Desktop.
Save jonleverrier/0da9345f6b4eb1e2be881891ae3e9a2b 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
/**
* getFromSteps v.1.0
* An unoffical utility snippet for Formalicious by Sterc
*
* This utility snippet outputs all the steps for a multistep form
* based on a given form ID
*
* Usage:
* Put the snippet in your &stepTpl and call the snippet like this:
* [[!getFormSteps? stepFormId=`[[!+form_id]]` &tpl=`myFormStepsTpl`]]
*
* Useful placeholders for the snippet tpl are:
* [[+currentStep]]
* [[+title]]
* [[+rank]]
*
* More info: https://forum.modmore.com/t/output-all-form-steps/1646
*
*/
// get the id of the form
$stepFormId = $modx->getOption('stepFormId', $scriptProperties);
// if there is no form id, stop here...
if (empty($stepsFormId)) {
return;
} else {
// get related steps
$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 is defined in the snippet call, output an array
$output[] = "<pre>" . print_r($placeholders, true) . "</pre>";
}
}
}
return implode("\n", $output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment