hybridinteractive / craft-contact-form-extensions

Adds extensions to the Craft CMS contact form plugin.
MIT License
43 stars 36 forks source link

Form Overrides not working #167

Closed JMKelley closed 1 year ago

JMKelley commented 1 year ago

Hi, having an issue with a form where no overrides are working.

Please see the code below:

{% macro errorList(errors) %} {% if errors %} {{ ul(errors, {class: 'errors'}) }} {% endif %} {% endmacro %} {{ csrfInput() }} {{ actionInput('contact-form/send') }} {{ input('text', 'fromName', submission.fromName ?? '', { id: 'from-name', autocomplete: 'name', class: 'form-control mb-3' }) }} {{ submission ? _self.errorList(submission.getErrors('fromName')) }} {{ input('email', 'fromEmail', submission.fromEmail ?? '', { id: 'from-email', autocomplete: 'email', class: 'form-control mb-3' }) }} {{ submission ? _self.errorList(submission.getErrors('fromEmail')) }} {{ tag('textarea', { text: submission.message ?? '', id: 'message', name: 'message', rows: 10, cols: 40, class: 'form-control mb-3' }) }} {{ submission ? _self.errorList(submission.getErrors('message')) }} {% if craft.app.session.hasFlash('notice') %}

{{ craft.app.session.getFlash('notice') }}

{% elseif craft.app.session.hasFlash('error') %}

{{ craft.app.session.getFlash('error') }}

{% endif %}
` I'm still getting the default confirmation emails as well as subjects. My templates are under `_emails/supplier.twig` Thanks
rosskenney commented 1 year ago

I will have a look at this.

rosskenney commented 1 year ago

@JMKelley Is this craft 3 or 4?

JMKelley commented 1 year ago

Craft 4

On Tue, 13 Dec 2022, 17:30 Ross K, @.***> wrote:

@JMKelley https://github.com/JMKelley Is this craft 3 or 4?

— Reply to this email directly, view it on GitHub https://github.com/hybridinteractive/craft-contact-form-extensions/issues/167#issuecomment-1349197300, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPVLM4YMUVFWHV5DSUQLITWNCXD5ANCNFSM6AAAAAASZS7DYQ . You are receiving this because you were mentioned.Message ID: <hybridinteractive/craft-contact-form-extensions/issues/167/1349197300@ github.com>

JMKelley commented 1 year ago

Any luck? :)

rosskenney commented 1 year ago

Yeah, sorry I tested this yesterday and figured it out today.

image

You can't just use message as it will overwrite the array that is being built. You need to change it to something like message[message]. I just added a note about this in the readme.

Note: All of the overrides will use the message as an array and therefore if you want a message field it would be name=message[message]. If a name=message is used it will wipe out the array of overrides.

palomamtnez commented 1 year ago

Hi @rosskenney
I' having the same issue and neither the template or subject work. Im still receiving the default template and subject from my main config (it is not overwriting it). The formName works though. This is my code My email template is in templates/_emails/interest.twig


<form method="post" accept-charset="UTF-8"  class="mt-12 sm:mx-auto sm:flex sm:max-w-lg form">
                        {{ csrfInput() }}
                        {{ actionInput('contact-form/send') }}

                        <div class="form__field_wrapper min-w-0 flex-1">
                            {{ input('email', 'fromEmail', submission.fromEmail ?? '', {
                                id: 'from-email',
                                autocomplete: 'email',
                                class: 'form__field block w-full drop-shadow-lg',
                                autofocus: false,
                                required: true,
                                placeholder: 'Enter your email address',
                            }) }}
                            <label for="cta-email" class="sr-only">Email address</label>
                        </div>

                        <input type="hidden" name="message[message]" value="Expression of interest">
                        <input type="hidden" name="message[formName]" value="Expression of interest">
                        <input type="hidden" name="message[template]" value="{{ 'interest'|hash }}">
                        <input type="hidden" name="message[subject]" value="{{ 'Thank you for your interest'|hash }}">

                        <input type="hidden" name="fromName" value="" />

                        {{ craft.contactFormExtensions.recaptcha | raw }}

                        <button type="submit"
                                class="button form-submit big-btn block w-full sm:w-fit ml-0 sm:ml-4 mt-4 sm:mt-0">{{ site.buttonLabel|default('Get started')  }}</button>
                    </form>```
rosskenney commented 1 year ago

Hi @palomamtnez,

It is not message[subject] is is just subject to override that. If you want to override the confirmation subject it would be message[confirmationSubject]

The template overrides are as such message[notificationTemplate] and message[confirmationTemplate]

I assume you are using Craft 4 so please take note of all changes and additions to overrides listed in the README.md file.

palomamtnez commented 1 year ago

You're a life saviour. Thanks, that worked!