Using eForm with external chunks
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:
<?php $path = $base_path .'assets/templates/site/chunks/contact-form.html'; return file_get_contents($path); ?>
<?php $path = $base_path .'assets/templates/site/chunks/contact-report.html'; return file_get_contents($path); ?>
<?php $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.