Make eForm replace chunks and snippets

on 09-Dec-2009 | Comments ( 8 ) Tags: Evolution

eForm 1.4.6.6 and lower will not replace chunks and snippets found in the eForm template.

The solution is really simple and makes use of the modx APIs and eForm's eformOnBeforeFormParse event.

The eFrom template

Create the eform template testCSTpl and paste the following:

<form method="post" action="[~[*id*]~]">
    <input type="hidden" name="formid" value="testCS" />
    [[snippetInEFORM]]
    {{chunkInEFORM}}
    <input type="submit" name="submit" value="Submit">
</form>

The parsing snippet

Create the replaceChunksAndSnippets snippet

<?php
function replaceChunksAndSnippets(&$fields, &$templates) {
	global $modx;
	$templates['tpl']=$modx->mergeChunkContent($templates['tpl']);
	$templates['tpl']=$modx->evalSnippets($templates['tpl']);
	return true;
}
?>

The snippet/eForm calls

[!replaceChunksAndSnippets!][!eForm? &formid=`testCS` &tpl=`testCSTpl` &eformOnBeforeFormParse=`replaceChunksAndSnippets` ... !]

Use the above solution with the one here and all your eForm resources can be kept in files.

Limitations:

  1. You can only use "cached" snippets: [[]]
  2. The eForm tags in your chunks and snippets will NOT be parsed by eForm.

Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.
 
Lissie Fein
Posts: 6
Comment
With TV's too?
Reply #8 on : Thu January 14, 2010, 13:34:11
Thanks, will this also work with TV's?
cipa
Posts: 2
Comment
Re: Make eForm replace chunks and snippets
Reply #7 on : Thu January 14, 2010, 14:37:04
I think it should. Just in case it does not work you can alway read a TV value with a snippet. Have a look into GetField snippet

<?php
return $modx->runSnippet("GetField", array('docid' => $id, 'field'=>'content'));
?>
LuK
Posts: 6
Comment
Multiple actions onBeforeFormParse?
Reply #6 on : Fri February 19, 2010, 07:25:04
Hi,

is it possible to insert multiple functions in the eform event functions?

Like:
LuK
Posts: 6
Comment
Re: Make eForm replace chunks and snippets
Reply #5 on : Fri February 19, 2010, 07:28:41
lol...it cut of my code...let's try again...

Like:
<code>

</code>
LuK
Posts: 6
Comment
Re: Make eForm replace chunks and snippets
Reply #4 on : Fri February 19, 2010, 07:30:40
Man...how did cipa post his code??

OK...without MODx Tags...I think eform kills the MODx Stuff^^^

lol...it cut of my code...let's try again...

Like:

!replaceChunksAndSnippets!
!eForm? &formid=`testCS` &tpl=`testCSTpl` &eformOnBeforeFormParse=`replaceChunksAndSnippets,anotherFunction,andAgainAnotherFunction` ... !


sorry for the spam...just delet what's not necessary =)
LuK
Posts: 6
Comment
Re: Make eForm replace chunks and snippets
Reply #3 on : Fri February 19, 2010, 07:40:23
I just found out that I already used a Snippet inside the eForm tplChunk...for some time now =)...

I have a Form on my 404 Error page where the User could supply the link he clicked on before he came to the error page...

Because I want to know where he came from I made a hidden Input (not type=hidden but hidden with css display: none, type=hidden did not work...)

looks like:

<!-- Referrer Field -->
<div class="input hidden">
<input type="text" name="err404ref" id="err404ref" value="((Referrer))" />
</div>

and the ((Referrer)) Snippet (had to replace the brackets...) gets...surprise...the referrer...but the user doesn't have to know that...I did that without any eform event functions...why does this work =)...? I use eform 1.4.6.(7) =D...
cipa
Posts: 2
Comment
Re: Make eForm replace chunks and snippets
Reply #2 on : Fri February 19, 2010, 11:32:53
Hi LuK,

I'm glad it works for you :). Maybe you have a newer version of eForm.

I'll have to investigate in order to give you a proper answer. Hopefully I'll figure this out on my next project. Let me/us if you find the answer.
thadk
Posts: 6
Comment
Other templates
Reply #1 on : Tue June 01, 2010, 15:34:31
if you need to run Chunks or snippets in the actual emails, you can take out the $templates['tpl'] and replace it with any of: tpl, autotext (aka automessage), report, thankyou (already seems to have no problem replacing).

Quick modx Evolution Tags

  • cached [[snippet]] or uncached [!snippet!]
  • {{chunk}}
  • [+placeholder+]
  • [*resourceField/TV*]
  • [^timing^]
  • [~link~]

Quick modx Revolution Tags

  • [[snippet]]
  • [[$chunk]]
  • [[+placeholder]]
  • [[*resourceField/TV]]
  • [[~link]]
  • [^timing^]
  • [[++systemSetting]]
  • [[%languageStringKey]]
  • all tags can be called un-cached like: [[! snippet]]

Timing Tags (Evo and Revo)

  • [^qt^] - Query time
  • [^q^] - Query count
  • [^p^] - Parse time
  • [^t^] - Total time
  • [^s^] - Source
© modxRULES! 2009-2014