This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
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
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 = 'mittul@technobrave.com';
//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
1-3 of 3