I’m new here and i’m currently doing a small website with some pages and forms.
I have a form that asks visitors to subscribe (like a newsletter for example but with more fields).
For this form I would like to be able to see the results either in the admin or on a specific front page.
It’s possible ? If yes, can you guide me on the procedure to follow?
Thanks for your help guys! @pikim i’ve already have the data saved in a txt file but is not an effective solution for viewing the results. @anon76427325 i think i’m going to do it with flexobjects, it seems the best option. My need look similar with the contacts directory with more informations!
But now I have another problem, there is no part on flex forms in flexobjects documentation ? Can i connect any form to my contacts directory in flex objects ?
Oh i think i’ve the solution… The save method works for save the data in right place.
But (yes another problem…) how can i save in json format? For now it’s just a .txt file…
I see. When you find a solution for storing the frontend form values in a json file I would be very interested in it. I could use it for my own page where people can register for a specific event and I could view the participants, then.
For testing purposes I already ported the guestbook plugin to flex-objects. But there I also would need to be able to store frontend form data (not on admin interface) as json.
I started to revise the guestbook plugin to use flex-objects instead of the conventional admin interface. You can find a first version on GitHub - pikim/grav-plugin-guestbook: Grav Guestbook Plugin. It already reads and displays existing entries and allows their deletion. Also new entries can be added. The included flex-blueprint is based on the one from the contacts example, so you can compare the both and see what has (to be) changed.
Currently, writing the form data into the json-file doesn’t work. I tried it with
{% macro render_field(form, fields) %}
{% set array = [ ] %}
{% for index, field in fields %}
{% set key = field.name %}
{% set value = form.value(field.name) %}
{% set array = array|merge({ (key): value}) %}
{% endfor %}
{% set array = array|merge({ "moderated": 0}) %}
{% set code = random_string(15)|md5 %}
{{ { (code): array }|json_encode|raw }}
{% endmacro %}
{{ _self.render_field(form, form.fields) }}
as standard save/add action which creates nicely formatted json, but appends each entry as a root entry. So, in the end the json file has an invalid format and a custom action like the one above from @anon76427325 is necessary.
Search for onFormProcessed in guestbook.php of my repo above. This is the function being called when the form is transmitted. You’ll have to put your custom code to store data there, as the standard save/add action doesn’t work with json files because of the root brackets {}.
I think there is some mistake in the flex-blueprint or the form page which leads to columns=null. Try to output some debug information at the code section where it’s created.
Do you know why in some older plugins the subscription is split into getSubscribedEvents and onPluginsInitialized? Was this the former state of the art?
@pikim, I’m sorry to say that I’m not a fan of your forked Guestbook plugin. It is based on a 7 years old plugin using a structure from the early days of Grav. Please have look at how a proper plugin skeleton is generated using $ bin/plugin devtools new-plugin.
I already used the plugin on my site as it is, but the admin interface doesn’t work. So it was just a first draft to see whether I understand the principle of flex-objects as I may have some more use cases in the future. I’ll think about updating it to a recent skeleton.
Formatting:
If the layout of your form is as you’ve shown, it is incorrect… If the form definition is not as shown, then please add some proper formatting:
we might then see if there are issues with the form definition.
and as a courtesy to the reader. Should the reader put effort in understanding the form, or should the author put effort in showing a proper form definition?
Context:
There should always be some context.
Is this a front-end form definition, or a form definition inside a flex-object blueprint, or …
If it is a font-end form, how is the form being processed:
Using a save action?
Or a custom action processed by a custom plugin?
Suggestion, if this is a front-end form and you are using a custom plugin to process the form, what are the values of $form->data['your-field-name']?
yes obviously i forgot some context… My apologies for this…
Here is some more informations about what i need to do :
I’ve one page (homepage) who contains some sections with the last one is a form section. This form is used for register people who participate at the event.
For now i’ve no custom plugin to do this, it’s juste a form with save action (see in md below)