Create a snippet called getFormSteps and place the following code inside it:
<?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]]
*
*/
// 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);
}
In stepTpl add the following example markup somewhere in your template:
Hi,
This is exactly what i want to achieve so thanks for posting.
However i can’t get it to work and wonder if you (or anyone else could help).
The form doesn’t display when your code is executed but the new html is present.
This is the html generated:
< form action=“test2.html?step=1” method=“POST” enctype=“multipart/form-data” novalidate="">
< div class=“c-stepprocess”>
< ol class=“c-stepprocess__items”>
</ ol>
</ div>
< input name=“submit-form5” value=“Next” type=“submit”>
</ form>
@9thwave - I can’t edit my original post, but since the last Formalicious update (1.4.4-pl) there is a new final step that is required to get this working, plus a slight template change to step 2.
The complete steps are:
Create a snippet called getFormSteps and put this inside it:
<?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
*
*/
// 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);
}
Create a chunk called stepTpl and put this inside:
I tried that call in the resource content area and as a chunk and i get a blank page with the following html. It only displays as expected on the front end when i use two calls. but the steps are then not rendering as expected;
< div class="c-form">
< legend class="c-form__legend">< /legend>
< div class="c-stepprocess">
< ol class="c-stepprocess__items">
< /ol>
< /div>
< div class="c-form__groups">
< /div>
< /div>
I’ll keep trying to see if i can suss what’s happening.
Re steps - yes of course. I can style them as necessary.