Tutorial "Frontend Form"

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

Some steps ahead:

  1. Create a partial contactForm
<form data-request="onContactForm" data-request-update="contactForm: '#contact-form'">
.. your form fields ..
</form>
  1. On page create a container (div) with id
<div id="contact-form">
{% partial 'contactForm' %}
</div>
  1. 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?

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!