Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Form post issue

Started by Muut Archive 11 years ago · 11 replies · 501 views
11 years ago

Hi all,
I've a strange issue. When validating my contact form with deliver theme, I'm having the following messsage The requested URL /contact was not found on this server. The requested url seems ok, as I'm coming from it. It drive me crazy.
I didn't modify the default .htaccess didn't modify the files from de Template.
I'm wondering if the following file is ok. the part with the action: /contact from modular_alt.md under contact directory in /user/pages/

YAML

title: Contact Us
onpage_menu: false
body_classes: "modular header-lite fullwidth"
bg_color: "#B4B093"
form:
    name: uxware-contact-form
    action: /contact
    fields:
        - name: name
          id: name
          label: Nom
          classes: form-control form-control-lg
          placeholder: Entrez votre nom
          autocomplete: on
          type: text
          validate:
11 years ago

Not sure why it shouldn't work, if /contact is a valid URL. Try sending me the user/ folder on a PM in Gitter, so I can test locally and see if I can recreate it.

11 years ago

hmm in your routing is your contact page set? of you only try to redirect from the form action. but the routing for the page hasn't set yet then it wont work.

11 years ago

No, no routing for this page yet. I took the skeleton, made some small modifications and made my pages.

11 years ago

I've tried to download a fresh skeleton deliver theme install on another server. The contact form seems to work.
After submitting, it's another message, the contact page is found and it's saying Oops there was a problem, please check your input and submit the form again
I've activating the debug in the system.yaml and the $_post is an array with the data filled before. I wonder what this message seems ?
thanks in advance.

11 years ago

I've founded it and it seems to be a validation error. Very strange how a form with a simple name, an email and a single message can't be valid ? And when we can see it in the $_POST with debugger. :-)
Still digging.

11 years ago

The error comes from a missing nonce token. This is needed in forms. The theme was built before this mechanism was introduced, I checked it and it missed the proper snippet to add the token verification, I added it: https://github.com/getgrav/grav-theme-deliver/commit/483bfe3e550bfeb6f8a3c8d28ecc7946bd15c66f

Not all themes extend and customize the form code, this does and it needed an update too, to this part handling forms.

Just add this to your theme too, without having to wait for a release.

11 years ago

I've already added this and it's the same situation. this oops ...

11 years ago

I've verified both user\plugins\form emplates\forms\default\form.html.twig

TWIG
{% if form.message %}<div class="alert">{{ form.message }}</div>{% endif %}
{% 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 %}

<form name="{{ form.name }}"
      action="{{ form.action ? base_url ~ form.action : page.url }}"
      method="{{ method }}"{{ multipart }}>

{% for field in form.fields %}
    {% set value = form.value(field.name) %}
    <div>
        {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %} 
    </div>
{% endfor %}

    <div class="buttons">
    {% for button in form.buttons %}
        <button class="{{ button.classes|default('button') }}" type="{{ button.type|default('submit') }}">{{ button.value|default('Submit') }}</button>
    {% endfor %}
    </div>

  {{ nonce_field('form', 'form-nonce') }}

</form>

and the user hemes\deliver emplates\forms\form.html.twig

TWIG
<div class="alert">{{ form.message }}</div>

<form name="{{ form.name }}"
      action="{{ uri.rootUrl ~ (form.action|default(page.route)) }}"
      method="{{ form.method|upper|default('POST') }}">
{% for field in form.fields %}
    {% set value = form.value(field.name) %}
    <div>
        {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
    </div>
{% endfor %}

    <div class="buttons">
    {% for button in form.buttons %}
        <button class="button" type="{{ button.type|default('submit') }}">{{ button.value|default('Submit') }}</button>
    {% endfor %}
    </div>

    {{ nonce_field('form', 'form-nonce') }}

</form>
11 years ago

Check that the nonce field appears in the HTML code geneated by the form correctly, just before the closing </form> tag

11 years ago

yes, the field is just before the </form> tag.

TXT
<input type="hidden" id="form-nonce" name="form-nonce" value="e365ea7c808da4ddecfb3eb4810bb4b2" pmbx_context="7A3DBE3E-4705-4EB3-8E22-102C7839F823">
11 years ago

Here is the field after submit and the famous oops message
<input type="hidden" id="form-nonce" name="form-nonce" value="ddcaa8cad51d843f368a6025cecd5967" pmbx_context="2911A7C3-830A-4481-A8A6-7EFD4FCCC63A">
The values are different, is it normal ?

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1351 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4063 9 years ago
Archive · by Muut Archive, 9 years ago
1 2948 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago