部分中的自定义联系表单,并在“静态页面"插件中使用 [英] Custom Contact Form in Partials and use in Static Pages plugin
问题描述
我使用了 OctoberCMS ,
I have used OctoberCMS, Static Pages plugin, through which I am creating Static Pages.
问题是,我在Partial中创建了一个联系表单,如下所示.
The thing is, I have created one contact form in Partial like below.
contactform_snippet.htm-标记
contactform_snippet.htm - Markup
contactform_snippet.htm-代码
contactform_snippet.htm - Code
下面是我创建的静态页面,并使用了我刚刚创建的 contactform_snippet.htm .
And below is the Static Page which I have created and used contactform_snippet.htm which I just created.
下面是预览的样子.
问题是,即使我单击提交"按钮,也没有执行任何操作.
The thing is, Even if I click on "Submit" button, it is not doing anything.
我还将表单代码从data-request="{{ __SELF__ }}::onSendInquiry"
更改为data-request="onSendInquiry"
,但是随后出现以下错误提示:
I also changed the form code from data-request="{{ __SELF__ }}::onSendInquiry"
to data-request="onSendInquiry"
but then I am getting below error saying:
未找到AJAX处理程序'onSendInquiry'.
AJAX handler 'onSendInquiry' was not found.
这是我在 CMS页面中创建并复制的类似内容,而不是在静态页面中复制的,所有这些都在其中进行验证和发送电子邮件.
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.
因此,我的问题是如何使用代码段在此处的静态页面中使同一事物工作.我知道可以通过创建 Components 来实现,但是我有很多表格,因此我想实现这样的功能以使其正常工作.有什么想法我需要在这里进行这项工作吗?
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 ?
谢谢
推荐答案
好,我最终通过将我的data-request="onSendInquiry"
放在表单中,并在下面的代码中放入了我的 default.htm strong>布局文件.
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
这篇关于部分中的自定义联系表单,并在“静态页面"插件中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!