Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 附加文件已停止工作十月CMS电子邮件ajax表单_Javascript_Php_Jquery_Ajax_Octobercms - Fatal编程技术网

Javascript 附加文件已停止工作十月CMS电子邮件ajax表单

Javascript 附加文件已停止工作十月CMS电子邮件ajax表单,javascript,php,jquery,ajax,octobercms,Javascript,Php,Jquery,Ajax,Octobercms,下面的设置一直工作到它停止,现在我很困惑为什么。 我已经在OctoberCMS中创建了一个带有文件附件的联系表单,如下所示 {{ form_ajax('ContactForm::onSend', { files: 'true', flash: 'true', 'data-request-files':true, 'data-request-validate': true }) }} <input type="hidden" name="handler" value='onSave

下面的设置一直工作到它停止,现在我很困惑为什么。 我已经在OctoberCMS中创建了一个带有文件附件的联系表单,如下所示

{{ form_ajax('ContactForm::onSend', { files: 'true',  flash: 'true', 'data-request-files':true, 'data-request-validate': true }) }}
    <input type="hidden" name="handler" value='onSave'>
    <fieldset class="form">
        <input type="name" name="name" placeholder="Imię i nazwisko" required>
        <input type="email" name="email" placeholder="E-mail" required>
        <input type="phone" name="phone" placeholder="Telefon">
        <input type="text" name="subject" placeholder="Temat" >
        <textarea name="theMessage" placeholder="Zapytanie" required style="width: 100%; height: 140px;"></textarea>
        <input type="file" name="fileAttachment" id="fileAttachment" class="inputfile"  data-multiple-caption="wybrano {count}" /><label for="fileAttachment">wybierz plik </label><span class='attachmentName'></span>

    </fieldset>
        <button type="submit" class="send" data-attach-loading>Wyślij</button>
    </fieldset>

{{ form_close() }}
{form_ajax('ContactForm::onSend',{files:'true',flash:'true',数据请求文件:true,'data request validate:'true}}}
威比尔兹普利克
威利
{{form_close()}}
用于发送电子邮件的组件

<?php namespace Depcore\Parts\Components;
use Cms\Classes\ComponentBase;

use Mail;
use Lang;
use Flash;
use Input;
use Validator;
use ValidationException;
use Redirect;
use System\Models\File;

class ContactForm extends ComponentBase
{
    public function componentDetails()
    {
        return [
            'name'        => 'depcore.parts::lang.components.contactFormTitle',
            'description' => 'depcore.parts::lang.components.contactFormDescription'
        ];
    }

    public function defineProperties()
    {
        return [
              'emailTo' => [
                    'title' => 'depcore.parts::components.emailAddress',
                    'description' => 'depcore.parts::components.destinationEmailDescription',
                    'default' => 'zamowienia@kludi.pl',
                    'validationPattern' => "\A[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z",
                    'ValidationMessage' => ''
            ]
        ];
    }

    public function onSend(){

        $data = post();
        $vars = [
            'name' => Input::get('name'),
            'subject' => Input::get('subject'),
            'phone' => Input::get('phone'),
            'theMessage' => Input::get('theMessage'),
            'fileAttachment' => Input::file('fileAttachment'),
        ];

        $rules = [
                'name' => 'required',
                'email' => 'required|email'
            ];

        $validator = Validator::make($data, $rules);

        if ($validator->fails())
            throw new ValidationException( $validator );
        else {

        Mail::send('depcore.parts::mail.message', $vars, function( $message )  use  ( $vars )  {

            // $message->to($this->property('emailTo'));
            $message->to('adam@depcore.pl');

            if ($vars['fileAttachment']) {
                $file = (new File())->fromPost($vars['fileAttachment']);
                $message->attach($file['path']);
            }

            $message->subject($vars['subject']);
            Flash::success('Wiadomość została wysłana.');
        });

      }
    }

}

从您的代码来看,您似乎错误地使用了错误的方法

 $vars = [
        'name' => Input::get('name'),
        'subject' => Input::get('subject'),
        'phone' => Input::get('phone'),
        'theMessage' => Input::get('theMessage'),
        'fileAttachment' => Input::get('fileAttachment'), <-- here
 ];

然后检查它,它应该能工作

更多更新 我添加了ajax框架的修改版(添加了js代码段),代码取自10月份cms官方git repo,只是删除了其中的一部分,这样它就可以覆盖现有代码而不会产生冲突

我建议,使用这段代码创建ajax-fw-override.js文件,然后在页面上包含该文件,或者只是复制布局并将其添加到最底部,不管它如何在10月份默认的ajax{%framework%}之后添加,这样它就可以覆盖其请求

这不是一个好的解决方案但考虑到您无法更新cms版本,我们可以使用它。(同样,通过复制布局,我们确保它不会影响其他任何地方)

我使用控制台在您的站点上测试了它,它成功了。所以只要看看,让我知道


+函数($){
“严格使用”;
var请求=函数(元素、处理程序、选项){
var$el=this.$el=$(元素);
this.options=options |{};
/*
*验证处理程序名称
*/
if(处理程序===未定义){
抛出新错误('未指定请求处理程序名称')
}
如果(!handler.match(/^(?:\w+\:{2})在*/)上){
抛出新错误('处理程序名称无效。正确的处理程序名称格式为:“OneEvent”。)
}
/*
*准备选项并执行请求
*/
var$form=options.form?$(options.form):$el.closest('form'),
$triggerEl=!!$form.length?$form:$el,
上下文={
处理者:处理者,
选项:选项
}
$el.trigger('ajaxSetup',[context])
var\u event=jQuery.event('oc.beforeRequest')
$triggerEl.trigger(\u事件,上下文)
if(_event.isDefaultPrevented())返回
var loading=options.loading!==未定义?options.loading:null,
isRedirect=options.redirect!==undefined&&options.redirect.length,
useFlash=options.flash!==未定义,
useFiles=options.files!==未定义
if(useFiles&&typeof-FormData==='undefined'){
console.warn('此浏览器不支持通过FormData上载文件')
useFiles=false
}
if($.type(加载)=='string'){
加载=$(加载)
}
/*
*请求头
*/
var requestHeaders={
“X-十月请求处理程序”:处理程序,
“X-10-REQUEST-PARTIALS”:此.extractPartials(选项.update)
}
如果(使用Flash){
requestHeaders['X-十月-REQUEST-FLASH']=1
}
/*
*请求数据
*/
var请求数据,
输入名称,
数据={}
$.each($el.parents('[data request data]')).toArray().reverse(),函数extendRequest(){
$.extend(data,paramToObj('data-request-data'),$(this.data('request-data'))
})
如果($el.is(':input')&&!$form.length){
inputName=$el.attr('name'))
if(inputName!==未定义&&options.data[inputName]==未定义){
options.data[inputName]=$el.val()
}
}
if(options.data!==未定义&&!$.isEmptyObject(options.data)){
$.extend(数据,选项.data)
}
如果(使用文件){
requestData=new FormData($form.length?$form.get(0):空)
if($el.is(':file')&&inputName){
$.each($el.prop('files'),function(){
append(inputName,this)
})
删除数据[inputName]
}
$。每个(数据、功能(键){
append(key,this)
})
}否则{
requestData=[$form.serialize(),$.param(数据)].filter(布尔值).join(“&”)
}
/*
*请求选项
*/
var请求选项={
url:window.location.href,
跨域:false,
上下文:上下文,
headers:requestHeaders,
成功:函数(数据、文本状态、jqXHR){
/*
*如果beforeUpdate()或更新前的数据请求返回false,则暂停此处
*/
if(this.options.beforeUpdate.apply(this,[data,textStatus,jqXHR])==false)返回
if(options.evalBeforeUpdate&&eval('(函数($el,context,data,textStatus,jqXHR){'+options.evalBeforeUpdate+'}.call($el.get(0),$el,context,data,textStatus,jqXHR))==false)返回
/*
*在窗体上触发“ajaxBeforeUpdate”,如果调用event.preventDefault()则暂停
*/
var\u event=jQuery.event('ajaxBeforeUpdate')
$triggerEl.trigger(_事件,[context,data,textStatus,jqXHR])
if(_event.isDefaultPrevented())返回
如果(使用闪存和数据['X\U十月\U闪存消息'])){
$。每个(数据['X\U十月\U快闪消息'],功能(类型,消息){
requestOptions.handleFlashMessage(消息,类型)
})
}
/*
*继续更新过程
*/
var updatePromise=requestOptions.handleUpdateResponse(数据、文本状态、jqXHR)
updatePromise.done(函数(){
$triggerEl.trigger('ajaxSuccess',[context,data,textStatus,jqXHR])
options.evalSuccess&&eval('(函数($el,context,data,textStatus,jqXHR){'+options.evalSuccess+'}.call($el.get(0),$el,context,data,textStatus,jqXHR)))
})
返回updatePromise
},
错误:函数(jqXHR、textStatus、errorshown){
var errorMsg,
updatePromise=$.Deferred()
如果((window.o
$file = (new File())->fromPost($vars['fileAttachment']);
$message->attach($file['path']);
$file = $vars['fileAttachment'];
$pathToFile = $file->getPathname();
$fileName = $file->getClientOriginalName();
$mime = $file->getMimeType()
$message->attach($pathToFile, ['as' => $fileName, 'mime' => $mime]);