mplodowski / formbuilder-plugin-public

https://octobercms.com/plugin/renatio-formbuilder
https://octobercms.com/plugin/renatio-formbuilder
2 stars 0 forks source link

Snippet Form cannot find AJAX Handler 'renderForm::onSubmit' #36

Closed sqwk closed 11 months ago

sqwk commented 1 year ago

When using the "Render Form Component" snippet inside a static page (variable, not the content field), the form gets rendered to the page but cannot be submitted. On submit an alert shows up "AJAX Handler 'renderForm::onSubmit' cannot be found" and the POST to the same page produces an error 500.

When using the "Render Form Component" component inside a CMS page, everything works fine.

October v3.4.15

Plugin v3.1.2

sqwk commented 1 year ago

The problem also occurs when downgrading the plugin to v3.0.0.

sqwk commented 1 year ago

Changing the registerPageSnippets() method inside Plugin.php to use an absolute class name seems to fix the problem:

public function registerPageSnippets()
{
    return [
        \Renatio\FormBuilder\Components\RenderForm::class => 'renderForm',
    ];
}
mplodowski commented 1 year ago

Hi,

I checked this and it seems to work find with example Contact Form.

October v3.4.15 Plugin v3.1.2 Pages plugin: v1.5.12

Hmm the most weird thing is that the change you made to make it work does not make any sense.

If you:

dd(
    [\Renatio\FormBuilder\Components\RenderForm::class => 'renderForm'],
    [RenderForm::class => 'renderForm'],
);

This is exactly the same, because first one use fully qualified name and the second shortcut with use import.

sqwk commented 1 year ago

OK, very weird. I undid the qualified name and it still works. So that was a false flag. Sorry, about that.

However, I noticed that when I edit the componentDetails()method inside RenderForm.php as below, the snippet code that is inserted in a static page changes to include <figure data-ajax=\"true\" ... and the snippet starts working.

public function componentDetails()
{
    return [
        'name' => 'renatio.formbuilder::lang.render_form.name',
        'description' => 'renatio.formbuilder::lang.render_form.description',
        'snippetAjax' => true
    ];
}

Could it be that the data-ajax is needed? (See https://docs.octobercms.com/3.x/cms/themes/snippets.html#creating-snippets-from-components)

mplodowski commented 1 year ago

Hi,

yes that is probably the issue here. This is a new feature of October, so I did not add it yet. Thanks for reporting this.

I published v3.1.3 where this is added.

Thanks for reporting this and help resolving this.

xmerlin commented 11 months ago

Same problem here FormBuilder 4.0.2, octobercms 3.5.4 (also 3.5.x)

"AJAX handler 'renderForm::onSubmit' was not found"

mplodowski commented 11 months ago

Hi @xmerlin,

please write me steps to reproduce this issue.

xmerlin commented 11 months ago

added {% styles %} in head added {% framework extras %} and {% scripts %} above script includes in the footer added standard "Contact Form" in the homepage

"AJAX handler 'renderForm::onSubmit' was not found." when I press send

mplodowski commented 11 months ago

Please copy your homepage and layout file source code. Just the minimum with the form and essential code.

xmerlin commented 11 months ago

layout

<!DOCTYPE html>

{% styles %} ...
{% partial "header" %} {% page %} {% partial "footer" %}
{% framework extras %} {% scripts %}

concact-form partial

Send us an Email

{% component "renderForm"%}
mplodowski commented 11 months ago

I assume that you use partial and put form component inside it.

Maybe this is the isssue: https://talk.octobercms.com/t/ajax-handler-in-php-section-of-partial/1009

https://docs.octobercms.com/3.x/markup/tag/ajax-partial.html

So instead of use {% partial 'contact-form' %} try to use {% ajaxPartial 'contact-form' %}

xmerlin commented 11 months ago

{% ajaxPartial 'contact-form' %} fixed the issue ...now I have to find why there is no message in the form log and/or in mailbox

mplodowski commented 11 months ago

I would check mail settings first. Go to Settings -> Mail Templates and click any mail template. There is a Sent test message button below. If you receive test message, then check Event Logs for any errors.

In form update page there is Options tab, where is setting to disable form logs. Check if it is not disabled.

Also to receive mail message the Mail Template field must not be empty.

xmerlin commented 11 months ago

Mail Template field empty ...now it works as expected, thank you