I have set up a component. That contains a form and then sends the filled form data to the admin to reply. but i keep getting an error from ajax “AJAX handler ‘onSend’ was not found.” i cannot figure out why that is. I know that previously this has worked i also set up a route to check if the emails are being sent out via SMTP and they are being sent out. Just for some reason the onSend isn’t found.
Folder structure
├── plugins
| └── myplugin
| └── kontakti
| ├── components
| | ├── contactform
| | | └── default.htm
| | └── ContactForm.php
| └── Plugin.php
My form from default.htm
<form data-request="onSend" id="contactForm">
/-- Fields --/
<div class="form-group submit">
<button class="form-group__submit" type="submit">{{ "Send_message"|_ }}</button>
</div>
</form>
Component initialization Plugin.php
public function registerComponents()
{
return [
'Cunamiweb\Kontakti\Components\ContactForm' => 'contactForm'
];
}
ContactForm.php
<?php namespace Cunamiweb\Kontakti\Components;
use Cms\Classes\ComponentBase;
use Input;
use Mail;
class ContactForm extends ComponentBase {
public function componentDetails() {
return [
'name' => 'Contact Form',
'descrption' => 'Contact Form That is used from user side to send questions'
];
}
public function onSubmit() {
$this->onSend();
}
public function onSend() {
\Log::info('onSend method called');
$vars = [
'name' => Input::get('name'),
'email' => Input::get('email'),
'phone' => Input::get('phone'),
'message' => Input::get('message')
];
Mail::send('cunamiweb.kontakti::mail.message', $vars, function($message){
$message->to('example@example.com', 'Admin');
$message->subject('New question from user');
});
}
}