Custom Contact Form in Partials and use in Static Pages plugin

这一生的挚爱 提交于 2019-12-08 13:31:18

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/43342871/custom-contact-form-in-partials-and-use-in-static-pages-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!