0

我已經使用OctoberCMSStatic Pages插件,通過它我創建靜態頁面。部分中的自定義聯繫表單和用於靜態頁面插件

事情是,我在下面部分創建了一個聯繫表單。

contactform_snippet.htm - 標記

enter image description here

contactform_snippet.htm - 代碼

enter image description here

而且下面是靜態頁面我已經創建和使用contactform_snippet.htm我剛剛創建。

enter image description here

及以下預覽怎麼看它像。

enter image description here

的事情是,即使我點擊「提交」按鈕,它沒有做任何事情。

我也改變了形式代碼data-request="{{ __SELF__ }}::onSendInquiry"data-request="onSendInquiry"但後來我得到以下錯誤說:

AJAX處理程序「onSendInquiry」沒有被發現。

這裏的事情是,我已經創建並在CMS頁,而不是複製靜態頁面,所有與驗證和電子郵件的工作有類似的事情被髮送。

所以我的問題是如何使用片段做同樣的事情,工作靜態頁面這裏。我知道可以通過創建組件來實現,但我有這麼多的表單,我想實現這樣的工作。任何想法我應該在這裏做這項工作需要什麼?

感謝

回答

0

好,大家好,最終我通過把我在我的形式做這個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; 
}] 

到目前爲止這麼接近。最後得到它。謝謝

相關問題