部分中的自定义联系表单以及在静态页面插件中的使用

问题描述 投票:0回答:1

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

问题是,我在Partial中创建了一个联系表单,如下所示。

联系表格snippet.html - 标记

enter image description here

联系表格snippet.html - 代码

enter image description here

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

enter image description here

下面是预览它的外观。

enter image description here

问题是,即使我点击“提交”按钮,它也没有做任何事情。

我还将表单代码从data-request="{{ __SELF__ }}::onSendInquiry"更改为data-request="onSendInquiry"but然后我收到以下错误说:

找不到AJAX处理程序'onSendInquiry'。

这里的事情是,我在CMS页面而不是静态页面中创建并复制的类似内容,所有这些都在验证和发送电子邮件。

所以我的问题是如何使用Snippets在静态页面中使用相同的功能。我知道可以通过创建组件来实现,但我有很多表单,我想实现类似的东西,使其工作。有什么想法让我在这里工作需要什么?

谢谢

php octobercms octobercms-backend octobercms-plugins october-partial
1个回答
0
投票

Ok Guys,最终我通过将我的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 = '[email protected]';
    //die($to);
    $params = compact('name','email','subject','msg');
    Mail::sendTo($to, 'yourappname.website::mail.contactform', $params);
    return true;
}]

到目前为止是如此接近。最后得到它。谢谢

© www.soinside.com 2019 - 2024. All rights reserved.