grav

Keep getting empty results when saving submission from form with Grav


I just started using Grav and I'm trying to create a form. The problem I have is that the file created don't show the form values.

Here is the code for my form :

title: Report an issue
form:
    name: report-issue
    fields:
        employee-id:
          label: Id
          autofocus: on
          autocomplete: on
          type: text
          validate:
            required: true
        
        employee-name:
          label: Name
          autofocus: on
          autocomplete: on
          type: text
          validate:
            required: true             
        
        more-info:
          label: Information
          placeholder: Add any relevant information
          style: vertical
          type: textarea
          validate:
            required: false

    buttons:
        submit:
          type: submit
          value: Submit
        reset:
          type: reset
          value: Reset
          
    process:
        - message: Thank you for your feedback!
        - reset: true
        - save:
              fileprefix: contact-
              dateformat: Ymd-His-u
              extension: txt
              operation: create
              body: "{% include 'forms/data.txt.twig' %}"

I played a bit with the twig file. This is what it looks like currently :

{% for field in form.fields %}
    <div><strong>{{ field.label }}</strong>: {{ string(field.value(field.name)|e) }}</div>
{% endfor %}

Problem I have is that it just saves the label, but not the inputted value.

For instance, this is the result I got after submitting my answer.

    <div><strong>Id</strong>: </div>
    <div><strong>Name</strong>: </div>
    <div><strong>Information</strong>: </div>

Solution

  • You are 'reset'-ing the form's data before saving it...

    Try:

    process:
      - message: Thank you for your feedback!
      - save:
        fileprefix: contact-
        dateformat: Ymd-His-u
        extension: txt
        operation: create
        body: "{% include 'forms/data.txt.twig' %}"
      - reset: true