(in json / flex format ) so that I can manage (in the backoffice) the feedback with a flex solution. I would be happy if there some example because I am not that good in creating a twig ans so.
@Karmalakas thanks for the answer. I took this as a start and finally found a solution.
The twig makes from a contact form a json record. I generate a unique random code as key.
{% macro render_field(form, fields) %}
{% set record = [ ] %}
{% for index, field in fields %}
{% set value = form.value(field.name) %}
{% set veld = field.label ~ ':' %}
{% set record = record|merge([veld, value]) %}
{% endfor %}
{% set code = random_string(15)|md5 %}
{{ { (code): record}|json_encode|raw }}
{% endmacro %}
{{ _self.render_field(form, form.fields) }}
However, when I try to read these records as a database by a flex object it fails.
I don’t know the solution for this or is the twig not good? Who does?
Or is there another solution that can be created FI a twig file where a front-end form can be presented as a flex-object?
As start I used https://github.com/trilbymedia/grav-plugin-flex-objects. Instead of “Contacts”, referred in this document, I created an own json file with records. I can add, edit, delete records in admin (the back office) and present them with pages in the front office.
What I want is that I can add records with a contact page ( front office) to this json file. With Admin I can edit the records or even delete then when action has taken place.
Hopefully this is more clear?
OK, so you want to save an object when someone fills the form on a page in front-end (front office)? If so, there are some bad news - flex objects still have some limitations:
Frontend only has a basic routing; for your custom tasks, such as saving, you need your own implementation
I probably don’t understand your problem at all. You asked how to save form data to JSON. I answered, but then you say that’s not what you actually need You need to read the data and not save it… I’m confused