Quote from: pixelchutes at Jan 08, 2007, 09:18 PM
Is there a way I can pass my dynamically created form (from a Snippet) for use within eForm (i.e. &tpl=`dynamicForm_fromSnippet` )
Want snippet-returned HTML for use in eForm? Here’s one way in 5 easy steps (line references from eForm v1.4.3)
I just implemented a solution for using Snippet-returned data as &tpl=`...` for eForm!
No more than a few lines required modification...still should be considered BETA, but you might want to check this out, because it’s working like a charm!
Here’s the snippet TPL implementation requirements:
replace lines 68-69 of:
//required
if( $tmp=efLoadTemplate($tpl) ) $tpl=$tmp; else return $_lang['ef_no_doc'] . " '$tpl'";
with:
// Modification by pixelchutes Allows for snippet-returned dynamic forms (3:17 PM 1/8/2007)
if( empty( $tpl ) and !empty( $tplSnippet ) ) $tpl = $tplSnippet;
//required # Modification by pixelchutes (pass optional tplSnippet)
if( $tmp=efLoadTemplate($tpl,$tplSnippet) ) $tpl=$tmp; else return $_lang['ef_no_doc'] . " '$tpl'";
Since other line references below depend on it, ensure that line 71 reads:
//required # Modification by pixelchutes (pass optional tplSnippet)
Let’s continue. Now, update new line 1014 to:
function efLoadTemplate($tpl,$tplSnippet=null){ // pixelchutes (tplSnippet param)
replace lines 1025-1026 of:
}else if($tpl)
$tpl = ( $chunk=$modx->getChunk($tpl) )? $chunk : false;
with this:
}
// Next 4 lines modified by pixelchutes to allow eForm templates from a snippet ( 2:59 PM 1/8/2007 )
else if( $tpl and empty( $tplSnippet ) )
$tpl = ( $chunk=$modx->getChunk($tpl) )? $chunk : false;
else if( $tpl == $tplSnippet )
$tpl = ( $snippet=$modx->runSnippet( $tplSnippet ) )? $snippet : false;
Then, update the eForm snippet itself to check for
&tplSnippet=`...`, by adding the following to the $params array
NOTE: I added mine on line 59, right after
tpl => isset($tpl)? $tpl:"",
tplSnippet => isset($tplSnippet)? $tplSnippet:"", // Added by pixelchutes
Finally, in the snippet call, don’t pass &tpl, rather &tplSnippet=`MySnippet_returnsHtmlForm`
e.g.
[!eForm? &formid=`myform` &tplSnippet=`MySnippet_returnsHtmlForm` !]
What’s so great is that I was able to port our Assessment/Survey system directly into eForm! With dynamic questions, and answer options/types (numeric, string/checkbox, radios, etc) a few simple rules to build out the form with
eform="..." on the <input>, and now we have validation options, email capabilities, as well as post-processing through event functions right out of the box
NOTE: This is just a personal, temporary solution. The primary fall back with this approach is that other templates (thankyou, report, etc) aren’t included. I’ve sent TobyL the idea, and he said he’ll be looking into a more generic solution specifically so that you can apply this to any of the templates