<?php
if(!function_exists("beforeParseFunction")){
//Display different form depending on session
function beforeParseFunction( &$fields, &$templates ){
global $_lang;
//which form should we load?
// $step is set in beforeMailSentFunction or comes from the hidden field
// we need to do both so that when we step back (eg. the back button of the browser)
// we still get the proper form
if(isset($_SESSION['formStep']))
$step = $_SESSION['formStep'];
else
$step = isset($_POST['formStep'])?$_POST['formStep']:1;
//Kill the session var as otherwise we can't go back to a previous step at all
unset($_SESSION['formStep']);
$tpl = $templates['tpl'];
// Replace form template when needed
switch($step){
case 1: //form not yet posted so use tpl as set in snippet call
return true;
case 2:
//build 2nd form using a snippet
$tmp = $modx->runSnippet('makeSecondForm',array('age'=>$fields['age'], 'gender'=>$fields['gender']) );
$tpl = ($tmp) ? $_lang['ef_no_doc'] . " 'second Form'";
break;
case 3:
if( $tmp=efLoadTemplate('multiForm3') ) $tpl=$tmp; else $tpl = $_lang['ef_no_doc'] . " '$replaceTpl'";
break;
default: //should never get here
return false;
}
//restore template in array
$templates['tpl']=$tpl;
return true;
}
}
?>
<?php
echo <<<END
<!-- Categories chunk -->
<h3>Starting: step 2 of 3</h3>
<p class="error">[+validationmessage+]</p>
<form method="post" action="[~[*id*]~]" id="contact">
<fieldset>
<input type="hidden" name="formid" value="contact" />
<input type="hidden" name="formStep" value="2" />
<p><select name="onderdeel">
<option value="0">Selecteer onderdeel</option>
<option value="193693">HD6</option>
<option value="193691">DD5</option>
</select>
</p>
<input type="submit" name="go" value="Next" /></p>
</fieldset>
</form>
END;
?>
<?php
if(!function_exists("beforeParseFunction")){
//Display different form depending on session
function beforeParseFunction( &$fields, &$templates ){
global $_lang;
//which form should we load?
// $step is set in beforeMailSentFunction or comes from the hidden field
// we need to do both so that when we step back (eg. the back button of the browser)
// we still get the proper form
if(isset($_SESSION['formStep']))
$step = $_SESSION['formStep'];
else
$step = isset($_POST['formStep'])?$_POST['formStep']:1;
//Kill the session var as otherwise we can't go back to a previous step at all
unset($_SESSION['formStep']);
$tpl = $templates['tpl'];
// Replace form template when needed
switch($step){
case 1: //form not yet posted so use tpl as set in snippet call
return true;
case 2:
//build 2nd form using a snippet
$tmp = $modx->runSnippet('eFormCategories',array('age'=>$fields['age'], 'gender'=>$fields['gender']) );
$tpl = ($tmp) ? $_lang['ef_no_doc'] . " 'FormTwo'";
break;
case 3:
if( $tmp=efLoadTemplate('FormThree') ) $tpl=$tmp; else $tpl = $_lang['ef_no_doc'] . " '$replaceTpl'";
break;
default: //should never get here
return false;
}
//restore template in array
$templates['tpl']=$tpl;
return true;
}
}
if(!function_exists("beforeMailSentFunction")){
//store results in session and advance form
function beforeMailSentFunction(&$fields){
global $modx;
$step = isset($fields['formStep'])?$fields['formStep']:1;
switch($step){
case 1: //save values in session
$_SESSION['age']= $fields['age'];
$_SESSION['gender']= $fields['gender'];
$_SESSION['formStep'] = 2; //prepare next step
break;
case 2: //save values in session
$_SESSION['address']= $fields['address'];
$_SESSION['town']= $fields['town'];
$_SESSION['formStep'] = 3; //prepare next step
break;
case 3://last form
//from here we go to the report so we need to restore previous values
// into the fields array so they can be used in the report
$fields['age'] = $_SESSION['age'];
$fields['gender'] = $_SESSION['gender'];
$fields['address'] = $_SESSION['address'];
$fields['town'] = $_SESSION['town'];
return true; //return now and let eForm do it's thing
default: //should never get here
return false;
}
// except for the last step we clear the $_POST array
// and bypass eform and re-open the page with the next form
unset($_POST);
$modx->sendForward($modx->documentIdentifier);
return false; //
}
}
//return from snippet
return "";
?><?php
$output = <<<END
<!-- Categories chunk -->
<h3>Starting: step 2 of 3</h3>
<p class="error">[+validationmessage+]</p>
<form method="post" action="[~[*id*]~]" id="contact">
<fieldset>
<input type="hidden" name="formid" value="contact" />
<input type="hidden" name="formStep" value="2" />
<p><select name="onderdeel">
<option value="0">Selecteer onderdeel</option>
<option value="193693">HD6</option>
<option value="193691">DD5</option>
</select>
</p>
<input type="submit" name="go" value="Next" /></p>
</fieldset>
</form>
END;
return $output;
?>
I do hope your snippet is going to do a bit more then that though, otherwise you can just as easily use chunks...
$tpl = ($tmp) ? $_lang['ef_no_doc'] . " 'FormTwo'";
$tpl = ($tmp) ? $tmp : $_lang['ef_no_doc'] . " 'FormTwo'";
That should have been:
$tpl = ($tmp) ? $tmp : $_lang['ef_no_doc'] . " 'FormTwo'";
Actually, I’ve read the documentation quite extensively. The debug parameter should be "Set to 1 for extended error messages in form validation", which I wasn’t looking for. My main issues were 25 million miles before that (switching on php error reporting fixed this).
And yes, you can enable debugging. It’s all in the eForm documentation, which off course you’ve read extensively... set the &debug parameter to 1,2 or 3 for different levels of debugging. However that wouldn’t have helped you much in this case.