We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45479
    • 18 Posts
    Hi there,
    I'm working with MODx just for some weeks now, but I'm amazed by it's capabilities. Sadly there are still some questionmarks:

    I got a problem with a form. The form itself works fine, the JS validation works just fine and the form gets sent and gets received. The problem is that the user doesn't get any confirmation after the form is sent. Of course I could rebuild the form with FormIt but I need a confirmation without a page refresh and I need the form gone after it got sent.

    This is the AJAX part, which calls a blank resource called "ajax-form" with just a snippet call on it.
    $(document).ready(function() {
        $("#reservation-form").validationEngine({
            ajaxSubmit: true,
            ajaxSubmitFile: "ajax-form",
            ajaxSubmitMessage: "Thanks for your message!",
            success :  false,
            failure : function() {}
        })
    });


    That's the content of the snippet:
    <?php
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    
    
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    
    $headers  = "From: XXX <[email protected]>\r\n";
    $headers .= "Reply-To: [email protected]\r\n";
    $headers .= "Content-Type: text/plain; charset=utf-8";
    
    $receiver = "[email protected]" ;
    
    
    if (!empty($name) & !empty($email) && !empty($message)) {
        $body = "Name: {$name}\n\nE-Mail-Adresse: {$email}\n\nNachricht: {$message}\n\n\n";
    	$send = mail($receiver, 'Nachricht über XXX', $body, $headers);
        if ($send) {
            echo 'true';
        } else {
    		echo 'false';
    	}
    }
    ?>


    Originally the ajaxSubmitFile was a php file like "contact.php". So my best guess is that the "true" out of the php doesn't get through to where it's needed, due to the detour over the resource "ajax-form".

    I appreciate any hints or tips!
      • 4172
      • 5,888 Posts
      what is the response, which you see, for example with firebug?
      which response is the 'validationEngine-script' waiting for?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 45479
        • 18 Posts
        Hi Bruno,
        the response was a "<p>true</p>". That was the reason why the mail got sent but nothing happened on the frontend because AJAX was expecting just "true".

        I spare you the account of my ordeal: the solution was to deactivate the rich text editor for the resource.

        Thanks for your impulse though!

          • 4172
          • 5,888 Posts
          Hi Lorenz,
          I've thought, it must be something like that and have allready seen your and Jako's posts.
          Thanks for reporting back.
          Glad you got it sorted.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!