Using eForm with external chunks

on 20-Sep-2009 | Comments ( 0 ) Tags: Evolution

In this tutorial I will create a simple "Contact Form" page that will be populated using external files, not regular HTML chunks.

By looking at eForm's code I found the following 2 lines:

$tpl = ( $doc=$modx->getChunk($key) )? $doc : false;
//try snippet if chunk is not found
if(!$tpl) $tpl = ( $doc=$modx->runSnippet($key) )? $doc : false;

As you can see eForm uses the runSnippet API but it does not take advantage of its parameters. Because of this limitation I had to create a snippet for each chunk used in my eForm call.

Let's start by saving the eForm templates to the server as files. In this case I choose to use the following path: 'assets/templates/site/chunks'

First file will be named: contact-form.html


Second file will be named: contact-report.html

This is a response sent by [+name+] using the contact form:


You can use this link to reply: [+email+]

Third file will be named: contact-thank-you.html

Thank you for your message!

I will get back to you as soon as possible.

The second step would be to create the 3 snippets that will load the above 3 HTML templates:


$path = $base_path .'assets/templates/site/chunks/contact-form.html';
return file_get_contents($path);


$path = $base_path .'assets/templates/site/chunks/contact-report.html';
return file_get_contents($path);


$path = $base_path .'assets/templates/site/chunks/contact-thank-you.html';
return file_get_contents($path);


All that is left is make the eForm call in the contact page template:

[!eForm? &formid=`contactForm` &to=`[(emailsender)]` &tpl=`getContactForm` &report=`getContactReport` &thankyou=`getContactThankYou` &subject=`Modx Rules - Contact Form`!]

How it works:

At first, eForm looks for a document ID then for an existing chunk and in the end tries to execute the snippet with the name you entered. As I mentioned above you cannot assign parameters for your snippet. If you know how to fix this limitation please leave a message.


Note: If you are looking for an @FILE solution take a look at this post.

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.

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