Contact form extending
Last updated
Was this helpful?
Last updated
Was this helpful?
There are five files that rule the contact form:
site/plugins/zero-one/snippets/contact/form.php
The frontend of the form
Controllers:
site/plugins/zero-one/controllers/contact.php
Controller used for the Contact template page
site/plugins/zero-one/controllers/site.php
Controller used for Page Builder contact form block.
Email templates:
site/plugins/zero-one/templates/emails/email.php
Plain text email template
site/plugins/zero-one/templates/emails/email.html.php
HTML email template
Basic knowledge needed
Before going further it is advisable that you have basic knowledge of how PHP contact forms work, and to read through these:
Basic Kirby contact form
How to properly extend Zero One
Let's say you want to add a new field "Company" to the form.
Copy site/plugins/zero-one/snippets/contact/form.php
to site/theme/snippets/contact/form.php
and open it with your code editor
Every field must have these attributes:
Unique
name
value
Optional
alert
This new field won't be required, but we will create some rule for it.
Copy site/plugins/zero-one/controllers/contact.php
To site/theme/controllers/contact.php
Now you must add new field data to that controller.
Add new rule for that field.
Add alert message for that new field.
And lastly, export that data to email.
Now, your new field is ready, the only thing left to do is add that data to email content.
Copy site/plugins/zero-one/templates/emails/email.php
To site/theme/templates/emails/email.php
And
Copy site/plugins/zero-one/templates/emails/email.html.php
To site/theme/templates/emails/email.html.php
Now add new "Company" field content to emails.
And that's it!
Your new field is connected and ready to go. You can add as many fields as you like.
also, open page to see what frontend options are available