I’m pretty sure this is a newbie question, ie something I’m not understanding about the way MODx parsing works.
OK, I have a form.
I have a bunch of code I recycle for all my non-CMS sites that basically use a php include at the top of the page ( processing code) for the processing and a form (contact form) with php in it on the page itself. The form calls the same page, the processing code validates, populates the form if some of the fields are wrong, sends the email when all is OK.
Works reliably.
I am trying to use this in MODx Evo without success.
I have made 2 snippets to include the php code, one at the top, one where the form is. Now they load OK with no errors but won’t talk to each other the way they normally do. ie I can’t populate my form from the processing code (or any of the other functions, status message)
I have gathered I can use eForm but I already have code I’m happy about customising for needs.
So what am I missing about these two snippets? or more likely about the way MODx parses my php
You should be able to just use one snippet, and do something like this (a very simple example):
Also note that you need to call the snippet uncached since it needs to be dynamic ( [!YourSnippetName!] )
<?php
$output ='';
if($_POST['submit']){
// form processing section
$output .='<p>Success view: the form was processed</p>';
}else{
// show the form
$output .='<p>Default view: your form goes here</p>';
}
return $output;
Hope that helps
Thank you it did - indirectly ;-)
The clue in your example was I can’t (for a reason I haven’t quite fathomed) pass variables directly from one snippet to another - the way I would do on a static page - so I simply combined both parts into one snippet, thereby not needing to return anything or pass variables around.
The reason is that the modx parser looks at each snippet like a function and each instance used is like a seperate entity. That said, I’ve found you can set a "$_SESSION[’blah’]" or create a "define(’BLAH’,’blah’)" in one snippet and use it in any other snippet on the page.