Quote from: sirlancelot at Jan 30, 2007, 05:11 PM
Once you parse the data from one of your steps you need to clear the $_POST data so that eForm goes in to normal mode instead of validation mode. I struggled with this issue for quite sometime on a related issue.
eForm detects the existence of $_POST data related to your form, since it still exists even AFTER you go to step 2, it will try to validate the data against step 2’s input. Clearing the $_POST data will solve the issue.
Alternatively, you can [tt]unset($_POST[’formid’]);[/tt] if you don’t want to completely destroy the $_POST array.
Yes, this is indeed the case! and something to be addressed in the example in the first post. I struggled with it just now trying this out again myself. Here the corrected functions for the example where the $_POST is cleared at the appropriate steps.
<?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:
$replaceTpl = "multiForm2";
break;
case 3:
$replaceTpl = "multiForm3";
break;
default: //should never get here
return false;
}
if($step>1)
if( $tmp=efLoadTemplate($replaceTpl) ) $tpl=$tmp; else $tpl = $_lang['ef_no_doc'] . " '$replaceTpl'";
//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;
$debugText .= "<b>BeforeMailSent: step=".$step."</b><br />";
switch($step){
case 1: //save values in session
$_SESSION['name']= $fields['name'];
$_SESSION['email']= $fields['email'];
$_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['name'] = $_SESSION['name'];
$fields['email'] = $_SESSION['email'];
$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 "";
?>
There is another complication however. eForm has evolved since the original example and you may find that the from never gets beyond the second form! Submitting the second form will simply display the same form again, without any values.
This is because in the newer eform versions it is no longer required to place the
formid in a hidden field. This field is normally added by eForm after reading the id from <form id="
contact"...> but because we are swapping the form
after this has happened eForm doesn’t see a proper formid and consequently doesn’t process the form.
To overcome this problem make sure that all the forms in the sequence have a hidden field for the formid. For the example form this would be:
<input type="hidden" name="formid" value="contact" />
Hope this solves your problem.