[英]Staying on same page after the form is submitted and then process the form again
我正在將Marketo(第三方營銷軟件)與我們網站上的一個工具集成在一起。
提交后,有一個表單可以調用“ http://info.a10networks.com/index.php/leadCapture/save ” 操作 ,並將表單數據保存到Marketo中:
<form
class="lpeRegForm formNotEmpty"
method="post"
enctype="application/x-www-form-urlencoded"
action="http://info.a10networks.com/index.php/leadCapture/save"
id="mktForm_1225"
name="mktForm_1225">
我想使用相同的表單數據將其存儲在本地數據庫(MySQL)中。 理想情況下,我希望在發送表單數據后加載相同的頁面,並在本地存儲此表單數據。
有沒有辦法執行以下操作:
$_POST
) 我正在使用PHP和普通的javascript進行這種集成。 請指教。
您可以使用ajax調用自己的腳本,然后將表單提交給marketo。
基本上,如果您希望在將數據發送到遠程服務器進行處理之前捕獲數據,則首先捕獲數據,然后允許表單提交並在之后執行其預期的處理。
在這里我們捕獲表單的單擊,然后確保通過向其添加類來禁用該按鈕。 因此,在處理完成之前,它不會讓用戶多次點擊。 當它完成收集信息並發送到你的php頁面時,它將表單提交給它的action
屬性。
在這個例子中,我從name屬性設置為firstName
的輸入中獲取值,該值將被發送到我的PHP腳本,因為我選擇了一種POST
我可以在我的POST
看到它
$_POST['firstName']
調試你的帖子參數以查看數據的樣子,以便在接收PHP腳本中進行調整
echo '<pre>', print_r($_POST, true), '</pre>';
這將顯示捕獲的數據。
<script type="text/javascript">
$(document).ready(function() {
$('.formSubmitButton').on('click', function(e) {
e.preventDefault();
if (!$('.formSubmitButton').hasClass('submitted'))
{
// disable the form to prevent multple clicks
$('.formSubmitButton').addClass('submitted');
$.ajax('/path/to/my/db/script', {
type: 'post',
data:{
firstName: $('[name="firstName"]).val(),
lastName: $('[name="lastName"]).val()
}
}).done(function(data) {
$('.parentForm').submit();
// enable the form
$('.formSubmitButton').removeClass('submitted');
});
}
return false;
});
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.