We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37946
    • 70 Posts
    I am calling the formIt snippet via an ajax request:
              $.ajax({
                    'type': 'post',
                    'contentType': 'application/x-www-form-urlencoded',
                    'url': '/contact/submit',
                    'data': $('#myForm').serialize(),
                    'dataType': 'json',
                    'timeout': 50000
                }).done(function(response) {
                    callback(response);
                }).fail(function(error) {
                    console.log('ERROR');
                    console.log(error);
                });
    


    Here is my runSnippet call:

    if ( trim( filter_var( $_POST['email'], FILTER_VALIDATE_EMAIL ) ) )
        {
            $output = $modx->runSnippet( 'FormIt', array(
                'emailTpl' => 'contactEmailTpl',
                'emailTo' => '[email protected]',
                'emailFrom' => '[email protected]',
                'emailFromName' => 'From Name',
                'emailSubject' => 'Contact Us'
                    ) );
    
            header( 'Content-Type: application/json' );
            return json_encode( array('status' => 'success') );
        }
    


    I am getting into the the method. For example if I put a log inside the 'if', I can see it in the log. But I'm not getting any sort of email. I'm sure it's something simple I'm missing - I've been looking at this page for a long time...

    Thank you for your time and suggestions!
      • 3749
      • 24,544 Posts
      I don't understand why you're calling FormIt from a processor called with Ajax. Why not just put a FormIt tag on the form page?

      FormIt has a lot of moving parts and doesn't send email by default. You'd have to specify the email hook in the arguments to runSnippet().

      If you're determined to use Ajax, I think QuickEmail might be a better option, since it's only function is to send email and the arguments would be simpler.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 37946
        • 70 Posts
        Well, I thought I could just call it like "normal" and it would be an easy deal. smiley
        I don't have to handle the form via AJAX, but was going to keep everything on the same page (no page reload). I think I'll just take your advice and roll with a traditional formit call.

        Thanks Bob!
          • 3749
          • 24,544 Posts
          I like to use JavaScript to do a complete validation of the form *before* it gets submitted. That does away with all the concerns about error placeholders and FormIt validation, and it makes the page seem much less antiquated, imo.

          See the SPForm JavaScript for an example.


            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting