Hello everyone
I am quite new to octobercms with advanced topics in Frontend. I normally use plugins for contactform etc. But now I want to create a own contact form and as far as I now in OctoberCMS it is possible without a plugin to create a contact form.
Is there any tutorial how to makes this? As I see there is the relax theme. Is this still a way to go with v.3
Thank you
snipi
January 12, 2023, 8:32pm
#2
Some steps ahead:
Create a partial contactForm
<form data-request="onContactForm" data-request-update="contactForm: '#contact-form'">
.. your form fields ..
</form>
On page create a container (div) with id
<div id="contact-form">
{% partial 'contactForm' %}
</div>
on page, where you put that partial, switch to code mode and make method onContactForm
function onContactForm() {
/// logic to process contact form, eg. send email with filled form, etc.
}
1 Like
Can you provide any logic for the contact form to send? I know there is the Relax theme - is this still a valide way to go?
Marcino
February 25, 2024, 8:03pm
#4
October provides really simple ways to integrate your mailing servers!
More can be found in docs Sending Mail - October CMS - 3.x
In sinipi’s example you’d want something similar to:
function onContactForm() {
$recipient = "recipient@email";
$data = Post();
if(isset($recipient)) {
Mail::sendTo($recipient, 'contact', [
'data' => $data,
]);
}
}
Then you can go to the main October settings and create new template like so
Please note that if you didn’t pre-configured a mailing server the email will just get logged.
Looks like Relax theme has some logic already prepared, but the above is quite universal way!