• Thanks for the nice lightweight plugin.

    Initially I was having some problems with it – I would try to submit a message on the contact form page, but it would respond with a “1” in a red box. However, the message still got sent.

    After digging around a bit, it seems that I had something (most likely in my plugin inventory) which had output a newline before the AJAX handler in inc/ef-ajax.php had been called. This was then throwing off the check for a plain “1” (without newlines) in essential-form.php, and making it think the call had failed.

    Would it be possible to add something like the following just before the “echo wp_mail()” call in ef-ajax.php? This should flush any extraneous buffered output before the echo. I know it’s not a problem with your plugin per-se, but it might fix some edge cases like this where other plugins etc. are not behaving properly.

    if ( ob_get_length() ) {
        ob_clean();
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jose Mortellaro

    (@giuse)

    Many thanks @sg213

    I suggest hooking into the essential_form_before_sending action to clear the output buffer:

    add_action( 'essential_form_before_sending',function() {
    if ( ob_get_length() ) {
    ob_clean();
    }
    } );

    Normally, the output buffer should be empty at this stage. If it isn’t, it usually means that another plugin or custom code has generated unexpected output during the AJAX request.

    While clearing the buffer is a valid workaround, I believe it’s better to identify and fix the original source of that output. Otherwise, the same issue could also affect other plugins or AJAX endpoints, not just Essential Form.

    For this reason, I would recommend using the snippet above as a temporary workaround while investigating which code is filling the buffer.

    I prefer not to add this behavior to the core of Essential Form. Automatically clearing the output buffer would hide problems caused by third-party code, making them harder to detect and fix. I think it’s better for Essential Form to provide a hook for custom workarounds when needed, rather than silently masking issues originating elsewhere.

    I hope it helps

    Have a great day!

    Thread Starter SG213

    (@sg213)

    Thanks for the detailed reply, yes that’s totally reasonable – I just thought I would post it here also in case anyone else had a similar issue and was trying to figure out what was happening. I’ll look again for the stray newline.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.