Sending, saving and updating a contact form.
william - 10 months ago
- As a visitor on a public page, i see a contact form.
- As a visitor i am able to fill out the contact form and submit it.
- As an admin, i receive a notification in my email when the form has been submitted.
- As an admin, i am able to view the form in the backend as well as edit it (or maybe fill out an extra field such as notes).
Displaying a form, using a handler to send the email as well as the builder saveForm is all taken care of and works. I am also able to see all submissions in the backend as an admin.
Question 1 If i want to show the admin an extra field that the public user don't see, i guess i basically just skip that field for the front end. Is that the preferred way of doing it?
Question 2 In my ContactFormBuilder (extending FormBuilder) i have this:
protected $actions = [ 'submit' => [ 'redirect' => false, 'text' => 'Send' ] ];
Works fine, outputting a send button to the front end. However, it also appears for the admin. Again, would i sort this out by building up the form in the front end using twig and outputting only the fields i want ? Or is there another way to control what buttons to be shown to the public user and what buttons to render for the administrator?
Question 3: In my ContactFormBuilder, i have my own handler set
protected $handler = ContactformFormHandler::class;
This is where i save the form as well as send the email. However, its not only called when a front end user submits the form, but also when an admin edit/saves the form in the backend. What is the best approach here. In its simplest scenario, i guess you could check the user and see if he is the admin and in that case not send the email, and just save the form.
But it feels messy, is there a good way to separate the view/logic from public user and the admin?