在 Partials 中自定义联系表单并在静态页面插件中使用

Custom Contact Form in Partials and use in Static Pages plugin

我使用了 OctoberCMS, Static Pages 插件,通过它我创建了静态页面。

事实是,我已经在 Partial 中创建了一个联系表,如下所示。

contactform_snippet.htm - 标记

contactform_snippet.htm - 代码

下面是我创建的静态页面,并使用了我刚刚创建的contactform_snippet.htm

下面是预览它的样子。

问题是,即使我点击 "Submit" 按钮,它也没有做任何事情。

我还将表单代码从 data-request="{{ __SELF__ }}::onSendInquiry" 更改为 data-request="onSendInquiry",但随后出现以下错误:

AJAX handler 'onSendInquiry' was not found.

这里的事情是,我在 CMS 页面 而不是 静态页面 中创建并复制了类似的东西,并且一切都在那里工作正在发送验证和电子邮件。

所以我的问题是如何使用 SnippetsStatic Pages 中实现相同的功能。我知道这可以通过创建 Components 来实现,但是我有很多表单,我想实现这样的东西来让它工作。任何想法我需要什么才能在这里工作?

谢谢

好的,伙计们,最终我通过将我的 data-request="onSendInquiry" 放在我的表单中并将下面的代码放在我的 default.htm 布局文件中来实现它。

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;
}]

如此接近却如此遥远。最后得到它。谢谢