【问题标题】:Get Form Element for Email Attachment获取电子邮件附件的表单元素
【发布时间】:2012-08-29 12:22:57
【问题描述】:

我假装将在输入类型文件中选择的附件内容传递到另一个 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);
    }
}

因此,我需要做的是将表单元素应用于此函数内的 var,以便我可以将她通过函数传递到这里:

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

所以这条线可以工作,因为现在它不工作。

希望我很清楚,我们将不胜感激。 谢谢哟!

【问题讨论】:

    标签: php javascript jquery forms email-attachments


    【解决方案1】:

    所以您想在提交之前更新表单操作?

    尝试像这样使用.submit() 事件和.attr()

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

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

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 2012-08-23
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 2019-03-07
      • 1970-01-01
      • 2017-09-06
      相关资源
      最近更新 更多