1

New to Craft CMS and trying to solve a mystery. When this contact form sends, the recipients don't get the email field. We get the others, including the consent, but the email field is missing. Any help would be appreciated.

Here's the code. Is there somewhere else it could be missing from?

{% macro errorList(errors) %}
    {% if errors %}
        {% includeJsFile(siteUrl~'js/validate-form.js') %}
        {% includeJsFile(siteUrl~'js/contact-scroll.js') %}
        <ul class="errors">
            {% for error in errors %}
                <li>{{ error }}</li>
            {% endfor %}
        </ul>
    {% endif %}
{% endmacro %}

{% from _self import errorList %}

<form method="post" action="" accept-charset="UTF-8" id="ask-scigrip">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="contactForm/sendMessage">
    <input type="hidden" name="redirect" value="contact/thanks">
    <input type="hidden" name="toEmail" id="toEmail" value="{{ 'info@scigrip.com'|hash }}">
    <input id="composite" name="composite" type="text">
    <div class="form-group">
      <p style="font-size:11px;text-align:left;padding-top:0;padding-left:0;">
        <strong>Your Data Permissions</strong><br>
        Under the new GDPR Regulations. We require your consent to use the above data we collect from you.
        We use this data to send you various communications for product updates and marketing purposes.
        This information will be sent by periodic emails to your email address.
        To enable us to do this you must check the below consent box.
        The data we hold for you will be inline with our privacy policy which can be <a href="/privacy-policy" target="_blank" style="color:#ffffff;text-decoration:underline;">viewed here.</a>
        <br>If you do not consent then we will only use your information for this enquiry and only hold it for the time it takes to finalise your request.
        <br><label for="gdprConsent" style="width: 100px;">I Consent</label><input id="gdprConsent" type="checkbox" name="message[GDPR][]" value="Consent Given" style="width:30px;margin-top:17px;">
      </p>
    </div>
    <div class="form-group">
    <label for="message">{{ 'POST YOUR QUESTION HERE' | translate }}</label>
    <input id="message" name="message[body]" value="{% if message is defined %}{{ message.message }}{% endif %}" required>
    {{ message is defined and message ? errorList(message.getErrors('message')) }}
    </div>
    <div class="form-group">
    <label for="fromEmail">{{ 'WHAT IS YOUR EMAIL?' | translate }}</label>
    <input id="fromEmail" type="email" name="fromEmail" value="{% if message is defined %}{{ message.fromEmail }}{% endif %}" required>
    {{ message is defined and message ? errorList(message.getErrors('fromEmail')) }}
    </div>
    <div class="form-group">
    <label for="firstName">{{ 'TELL US YOUR NAME' | translate }}</label>
    <input id="firstName" type="text" name="message[FirstName]" value="{% if message is defined %}{{ message.messageFields['FirstName'] }}{% endif %}" class="inp-sml">
    <button type="submit" id="submit" name="submit" value="SEND">ASK SCIGRIP <i class="glyphicon glyphicon-triangle-right"></i></button>
    </div>
    {#<div class="form-group">
    <input type="submit" value="Send">
    <button type="submit" id="submit" name="submit" value="SEND">SEND</button>
    </div>#}
</form>
0

If you go with the message[] array syntax, then all other fields must use the same syntax.

https://github.com/craftcms/contact-form#adding-additional-fields

So this should solve it:

<input id="fromEmail" type="email" name="message[fromEmail]" value="{% if message is defined %}{{ message.messageFields['fromEmail'] }}{% endif %}" required>
| improve this answer | |
  • I'm getting the following error on the form now: "Your Email cannot be blank." It's not registering the input for some reason? – Pirate727 Jul 30 '19 at 19:35
  • That validation error appears below the email field when I try to submit. – Pirate727 Jul 30 '19 at 19:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.