0

Platform:

  • Craft Solo 3.7.21
  • P&T Contact Form plug in 2.2.7
  • Redactor 2.8.8

I am trying to use the Contact Form plugin and having problems when using the latest version of the API. I have an old implementation from several years ago that works, but when upgrading to the most recent plugin example code get an error when trying to submit a form.

This works:

 <form method="post" action="" accept-charset="UTF-8" class="form1">
     {{ csrfInput() }}
                <input type="hidden" name="action" value="contact-form/send">
                {{ redirectInput('thanks?from={fromName}') }}
                <h2>Please enter the following:</h2>
                <div class="indicates-required"><span class="asterisk">*</span> indicates required</div>    
                <div class="mc-field-group"><label for="from-name">Your Name</label>
                    <input id="from-name" type="text" name="fromName" value="{{ message.fromName ?? '' }}">
                    {{ message is defined and message ? errorList(message.getErrors('fromName')) }}
                </div>
                <div class="mc-field-group">
                    <label for="from-email">Your Email <span class="asterisk">*</span></label>
                    <input id="from-email" type="email" name="fromEmail" value="{{ message.fromEmail ?? '' }}">
                    {{ message is defined and message ? errorList(message.getErrors('fromEmail')) }}
                </div>
                <div class="mc-field-group">
                    <label for="subject">Subject</label>
                    <input id="subject" type="text" name="subject" value="{{ message.subject ?? '' }}">
                    {{ message is defined and message ? errorList(message.getErrors('subject')) }}
                </div>
                <div class="mc-field-group">
                    <label for="message">Message <span class="asterisk">*</span></label>
                    <textarea rows="10" cols="40" id="message" name="message">{{ message.message ?? '' }}</textarea>
                    {{ message is defined and message ? errorList(message.getErrors('message')) }}
                </div>
                <input id="date" type="text" name="date">
                <div class="clear">
                    <input type="submit" value="Send" class="button">
                </div>
            </form>

This generates the following error message:

  • "There was a problem with your submission, please check the form and try again!"
<form method="post" action="" accept-charset="UTF-8" class="form1">
                
                {{ csrfInput() }}
                {{ actionInput('contact-form/send') }}
                {{ redirectInput('thanks?from={fromEmail}') }}

                <h2>Please enter the following:</h2>

                <div class="indicates-required"><span class="asterisk">*</span> indicates required</div>    
                
                <div class="mc-field-group">
                    <label for="from-email">Your Email Address</Address><span class="asterisk">*</span></label>
                    {{ input('email', 'fromEmail', message.fromEmail ?? '', {
                        id: 'from-email',
                        autocomplete: 'email',
                    }) }}
                    {{ message ? _self.errorList(message.getErrors('fromEmail')) }}
                </div>

                <div class="mc-field-group"><label for="first-name">First Name</label>
                    {{ input('text', 'firstName', message.firstName ?? '', {
                        id: 'first-name',
                        autocomplete: 'First Name',
                    }) }}
                    {{ message ? _self.errorList(message.getErrors('firstName')) }}
                </div>

                <div class="mc-field-group">
                    <label for="last-name">Last Name</label>
                    {{ input('text', 'lastName', message.lastName ?? '', {
                        id: 'last-name',
                        autocomplete: 'Last Name',
                    }) }}
                    {{ message ? _self.errorList(message.getErrors('lastName')) }}
                </div>
                <input id="date" type="text" name="date">
                <div class="clear">
                    <button type="submit">Subscribe</button>
                </div>
            </form>

Maybe the problem is obvious, but I'm not seeing it, so help is appreciated.
Thanks.

5
  • My guess is it's an email settings problem (Settings->Email in the Craft control panel). Try checking the Craft storage/logs folder for the underlying error.
    – Brad Bell
    Nov 16 at 19:26
  • Thanks, but Email works - I can send test emails, and as I say, with the old code the form is correctly submitted and the email sent. WRT log files, there are a bunch of them; which would I be most interested in checking?
    – g. eagle
    Nov 16 at 19:50
  • Try comparing the rendered HTML of the two versions and see if there are any obvious errors or differences? Nov 16 at 20:11
  • I tested your second code example and it didn't work, as you said. However, that code isn't the example from the Contact Form plugin documentation. It's missing the error list macro and has some other changes. I was able to get the contact form code from the documentation to work just fine. I would go back to that example and test that it works and then make your changes, one thing at at a time.
    – CraftQuest
    Nov 16 at 23:29
  • CraftQuest - You're right; the base demo code works, mine doesn't. Will do as you as you suggest and go through it line by line. Thanks.
    – g. eagle
    Nov 17 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.