Custom Contact Form In Partials And Use In Static Pages Plugin
I have used OctoberCMS, Static Pages plugin, through which I am creating Static Pages.
The thing is, I have created one contact form in Partial like below.
contactform_snippet.htm - Markup
contactform_snippet.htm - Code
And below is the Static Page which I have created and used contactform_snippet.htm which I just created.
And below is Preview how its looking like.
The thing is, Even if I click on "Submit" button, it is not doing anything.
I also changed the form code from data-request="{{ __SELF__ }}::onSendInquiry"
to data-request="onSendInquiry"
but then I am getting below error saying:
AJAX handler 'onSendInquiry' was not found.
The thing here is, similar thing I have created and copied in CMS Page instead of Static Page and all is working there with validations and email being sent.
So My question is how can make the same thing work in Static Pages here using Snippets. I know the can be achieved via creating Components but I have so many of forms and I want to implement something like this to make it work. Any thoughts what should I need to make this work here ?
Thanks
Answer
Ok Guys, Eventually I made it work by putting my doing this data-request="onSendInquiry"
in my form and putting below code in my default.htm layout file.
function onSendInquiry()
{
// Collect input
$name = post('name');
$email = post('email');
$subject = post('subject');
$msg = post('msg');
// Form Validation
$validator = Validator::make(
[
'name' => $name,
'email' => $email,
'subject' => $subject,
'msg' => $msg,
],
[
'name' => 'required',
'email' => 'required|email',
'subject' => 'required',
'msg' => 'required',
]
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
//Retrieving all error messages for all fields
/*foreach ($messages->all() as $message) {
throw new ApplicationException($message);
}*/
//throw new ApplicationException($messages);
}
// All is well -- Submit form
$to = System\Models\MailSetting::get('sender_email');
//$to = System\Models\MailSettings::get('sender_email');
//$to = config('mail.from.address');
//$to = '[email protected]';
//die($to);
$params = compact('name','email','subject','msg');
Mail::sendTo($to, 'yourappname.website::mail.contactform', $params);
return true;
}]
Was so close yet so far. Got it in the end. Thanks
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?