terminal42 / contao-ajaxform

Submit a form through ajax and display error or confirmation message.
15 stars 7 forks source link

Would like to still show the form after submission #16

Open bwl21 opened 3 years ago

bwl21 commented 3 years ago

We are using this for feedbacks in an embedded video. If the form was submitted, it confirms the submission by showing the Text specified in the embedding element.

But how can I display the form in addition to the confirmation text such that the visitor can send another one.

bwl21 commented 3 years ago

I tried to include the form again in the confirmation message

Ihre Meldung wurde verarbeitet.

{{insert_content::26857}}

but it appears that insert tags are not processed here.

bwl21 commented 3 years ago

Hallo,

I had a look into the sourcecode of the page. Maybe it can be solved in the script on the frontend

  1. Add a field "successresult" (HTML-Code or Explanation (can be done by the form designer)
  2. instead of replacing the entire form, only replace "successresult" and empty the other form fields

Maybe I can even append another script which every 5 seconds replaces the conformation text with the original form ... this is, what I will try first.

What do you think?

As a pity I have no experience with building Contao extensions, so I cannot prepare a PR.

bwl21 commented 3 years ago

I could solve the issue by adapting the template ajaxforms.html5:

        var responsediv = form.querySelector('.ajaxformresponse');
        if (responsediv) {
            responsediv.innerHTML = "Ihre Eingaben werden versendet";
        }

        request('POST', form.action, formData, function () {
            var location = this.getResponseHeader('X-Ajax-Location');
            if (!location) {

                form.innerHTML = form.innerHTML; // clear the form fields
                var responsediv = form.querySelector('.ajaxformresponse');

                if (responsediv) {
                    responsediv.innerHTML = this.responseText;
                } else {
                    updateContent(form, this.responseText);
                }
                return;
            }

            request('GET', location, null, function () {
                updateContent(form, this.responseText, location);
            });
        });

I have to add a field in the form with the class .ajaxformresponse in which messages can be placed.