Concrete5.7: External forms + Sending mail + Ajax -> a starting point?


I've been trying to figure out how to build a simple External Form which sends mail and submits via Ajax on Concrete5.7, but can't seem to get this thing working.

I am able to call my External Form's action that I've created in its Controller, BUT it returns a whole HTML-page on top of what ever I am trying to print out from it - as it probably should too in a non-Ajax environment. Is there a way to disable the page rendering on actions when using Ajax calls?

Also, when I try to use the Mail-helper, $mh = Loader::helper('mail');, in my action, it will return an Internal Server Error: "Class 'Concrete\Block\ExternalForm\Form\Controller\Core' not found".

I am kind of totally stuck with this problem. Is there a simple resource or tutorial showing how to achieve something like this?

Thanks a lot!

PS. Also for some reason Concrete5 only loads my External Form's Controller from the /concrete/blocks/external_form/form/controller -directory, instead of /application/blocks/external_form/form/controller -directory although its view-file is correctly loading from /application/blocks/external_form/form/. Don't know why this is happening either... a namespacing problem, maybe?

View Replies:
danielgwood replied on at Permalink Reply
To echo this, I'd love to see some documentation on this one too. If it is supposed to work like is implied from the "example", it doesn't work.

Just like the OP I couldn't get the controller file to load from /application/... either, but when I put exactly the same code in the core /concrete directory, it worked first time.

I've posted my code here:
danielgwood replied on at Permalink Reply
I now have a working external email form, in case it's of use to anyone. It doesn't use AJAX because I didn't see the need.

View code (located in application/blocks/external_form/form/contact_form.php):
defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Core\Validation\CSRF\Token;
<?php if(isset($response) && $response): ?>
    <div class="alert alert-info">Thanks, your email was successfully sent.</div>
<?php endif; ?>
<?php if(isset($errors) && !empty($errors)): ?>
    <div class="alert alert-error">
        <p>Sorry, there was a problem with your submission and your message could not be sent.</p>
            <?php foreach($errors as $field => $error): ?>
                <li><?php echo $error; ?></li>
            <?php endforeach; ?>

Controller code (located in concrete/blocks/external_form/form/controller as this is the only place it seems to work):
namespace Concrete\Block\ExternalForm\Form\Controller;
use Loader;
use Concrete\Core\Validation\CSRF\Token;
class ContactForm extends \Concrete\Core\Controller\AbstractController
     * Sends the email.
     * @return boolean
    public function action_send()
        $errors = array();
        // Load helpers

- I don't use the C5 form helpers to build my form HTML, as I don't see the need
- At the moment any input errors are all output in one block at the top, but you're welcome to put these inline, it's just a style thing
- I've used the C5 helper classes for validation and sanitisation where it made sense. I didn't load the whole lot because it's overkill for a simple form
- Not sure my usage of the C5 CSRF token class is exactly as intended, but it does work