2012-08-29 30 views
1

我假裝將在輸入類型文件中選擇的附件內容傳遞給另一個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; 

讓這條線可以工作,因爲現在它不工作。

希望我清楚,有一點幫助將不勝感激。 同比謝謝!

回答

2

所以,你要提交之前更新表單的動作?

嘗試使用.submit()事件和.attr()這樣的:

$('#formElem').submit(function(){ 

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

}); 

我這裏測試此邏輯:jsFiddle

希望幫助!