Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contact form #16

Closed
andyberkoff opened this issue Apr 27, 2017 · 6 comments · Fixed by #17
Closed

contact form #16

andyberkoff opened this issue Apr 27, 2017 · 6 comments · Fixed by #17

Comments

@andyberkoff
Copy link

Hey.
When working with this skeleton, I found a problem with the contact form. You forgot to add to the theme files form.html.twig and formdata.html.twig this led to the fact that sending a message from the contact form resulted in an error that the file was not found. No message was sent Thank you.

@pubmania
Copy link

pubmania commented May 4, 2017

I have a similar problem. Although the form.html.twig is there in the skeleton. I have found that when I use the form.html.twig from antimatter it allows sending the mail but the one that has come default with the theme it does not send mail. Using the one from antimatter screws up the layout's look and feel and hence am left with either an ugly contact form or one that isn't working.

Please can someone provide any guidance on how to make the contact form working on this theme?

@pubmania
Copy link

pubmania commented May 4, 2017

I compared the form.html.twig of form plugin and this theme and then made few changes. This has made the contact form work.
I added at:

  • Line 11 {% set scope = scope ?: 'data.' %}
  • Amended Line 20 (line 21 in new file) {% set action = form.action ? base_url ~ form.action : base_url ~ page.route ~ uri.params %}
  • Amended line 67 (line 68 in new file) {{ nonce_field('form', 'form-nonce')|raw }}

form.html.twig after my changes looks as below:

<section id="contact">
  <div class="container">
    <div class="row">
      <div class="col-lg-12 text-center">
        {{ content }}
      </div>
    </div>
    <div class="row">

{% if form.message %}<div class="alert notices {{ form.message_color ?: 'green' }}"><p>{{ form.message }}</p></div>{% endif %}
{% set scope = scope ?: 'data.' %}
{% set multipart = '' %}
{% set method = form.method|upper|default('POST') %}

{% for field in form.fields %}
    {% if (method == 'POST' and field.type == 'file') %}
        {% set multipart = ' enctype="multipart/form-data"' %}
    {% endif %}
{% endfor %}

{% set action = form.action ? base_url ~ form.action : base_url ~ page.route ~ uri.params %}
{% if (action == base_url_relative) %}
    {% set action = base_url_relative ~ '/' ~ page.slug %}
{% endif %}

<form name="{{ form.name }}"
      action="{{ action }}"
      method="{{ method }}"{{ multipart }}
      {% block form_classes %}
      {% if form.classes %}class="{{ form.classes }}"{% endif %}
      {% endblock %}
>

  <div class="col-md-6">
    {% for field in form.fields %}
      {% if field.position == 'left' %}
        {% set value = form.value(field.name) %}
        <div class="form-group">
          {% include "forms/fields/#{field.type}/#{field.type}.html.twig" ignore missing %}
        </div>
      {% endif %}  
    {% endfor %}
  </div>
  <div class="col-md-6">
    {% for field in form.fields %}
      {% if field.position == 'right' %}
        {% set value = form.value(field.name) %}
        <div class="form-group">
          {% include "forms/fields/#{field.type}/#{field.type}.html.twig" ignore missing %}
        </div>
      {% endif %}  
    {% endfor %}
  </div>

  <div class="col-lg-12 text-center">
      <div class="form-group">
        {% for button in form.buttons %}
          <button 
            {% block button_classes %}
            class="{{ button.classes|default('button') }}"
            {% endblock %}
            type="{{ button.type|default('submit') }}"
            >{{ button.value|t|default('Submit') }}</button>
        {% endfor %}
      </div>
  </div>

  {{ nonce_field('form', 'form-nonce')|raw }}
</form>

@codewinkel
Copy link

codewinkel commented Jun 8, 2017

Does it works for someone? I have still the same problems with sending mail. cli works
Also after the updates in the form.html.twig from the theme

OleVik added a commit to OleVik/grav-theme-agency that referenced this issue Jun 9, 2017
Some restructuring, formatting improvements. Tested with Grav v1.2.4, Form v2.7.0, Email v2.6.0, and Agency v1.4.0. Users should include a '/user/pages/01.home/thankyou/formdata.md' (per https://learn.getgrav.org/forms/forms/reference-form-actions#display) to verify that mails are sent on front-end.
@OleVik OleVik mentioned this issue Jun 9, 2017
@walkero-gr
Copy link

I had many problems to make it work. A solution I found was to follow pubmania's changes, but I also added the following code under line 54

{% include "forms/fields/formname/formname.html.twig" %}

@pubmania
Copy link

pubmania commented Jul 21, 2017

The changes I did earlier stopped working recently so I returned back to this page and I then added on line 54 the code suggested by @walkero-gr and it is working again.

I have also checked by replacing the /user/themes/agency/templates/modular/form.html.twig with that amended by @OleVik Fix#16#17 and it works perfectly fine too.

Although I do get worried with this manual approach - Why can't these changes be updated on the theme so users don't have to make these manually? Is there anything wrong with this approach?

@OleVik
Copy link
Contributor

OleVik commented Jul 21, 2017

There is not really a problem with the approach, but rather that changes need to be merged into the theme. We could ask @flaviocopes to do a review of #17, and consider the addition of the suggestion by walkero-gr above.

rhukster pushed a commit that referenced this issue Sep 28, 2017
Some restructuring, formatting improvements. Tested with Grav v1.2.4, Form v2.7.0, Email v2.6.0, and Agency v1.4.0. Users should include a '/user/pages/01.home/thankyou/formdata.md' (per https://learn.getgrav.org/forms/forms/reference-form-actions#display) to verify that mails are sent on front-end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants