获取电子邮件附件的表单元素


Get Form Element for Email Attachment

我假装将在输入类型文件上选择的附件的内容传递到另一个php页面,在那里我将通过电子邮件发送附件。

碰巧我有这样的表格声明:

<form id="formElem" name="formElem" enctype="multipart/form-data" action="" method="post">

但是我不能将目标php页面放在那里,因为我传递了一个jquery和一个javascript函数。在最后一个函数中,我重定向到目标php页面。

因此,在最后一个javascript函数中,我需要使用以下内容:

form.action = 'index.php?pagina=candB&'+ qstringA;

将表单的所有数据重定向到假装php页面。在我使用这个之前:

window.location.href = 'index.php?pagina=candB&'+ qstringA;

但正如我在这里被告知的那样,这将不允许正确接收附件的数据。

这是我提交的表单的按钮:

<button name='send_cand' id='send_cand' value='send_cand' onclick='return false;' type='submit'>Send Data</button>

它调用以下jquery函数:

$('#send_cand').bind('click',function(){
    ....
    if($('#formElem').data('errors')){
        preenchimentoForm=false;
        dadosFormularios(form, preenchimentoForm, cursos, empregos, eventos);
        return false;
    }
    else{
        dadosFormularios(form, preenchimentoForm, cursos, empregos, eventos);
    }
}

因此,我需要做的是将form元素应用于这个函数中的var,这样我就可以通过函数传递给她,直到这里:

form.action = 'index.php?pagina=candB&'+ qstringA;

这样这条线就可以工作了,因为现在它不工作了。

希望我很清楚,如果能提供一点帮助,我们将不胜感激。谢谢你!

那么您想在提交之前更新表单操作吗?

尝试使用.submit()事件和.attr(),如下所示:

$('#formElem').submit(function(){
    // Update the form action        
    $('#formElem').attr('action', 'index.php?pagina=candB&'+ qstringA);
});

我在这里测试了这个逻辑:jsFiddle

希望能有所帮助!