我们如何使用一种汇总形式将数据保存在两台服务器上? [英] How we can save data on two servers using one sumit form?
问题描述
我正在使用第三方工具.这是表格:
I am using third party tool. Here is form for that:
<form method="POST"
action="https://www.thewiseagent.com:443/secure/webcontactAllFields.asp"
name="myForm" onSubmit="return chkForm(this);">
<!-- Do not change -->
<input type="hidden" name="ID" value="67,176,210,31,93,194,29,70,235">
<!-- These fields can be edited -->
<input type="hidden" name="responsePage" value="http://http://www.expertforyou.com/">
<input type="hidden" name="Source" value="website referral">
<input type="hidden" name="Categories" value=""><!-- semicolon;delimited no spaces -->
<input type="hidden" name="currentUser" value=""><!-- internal team member -->
<input type="hidden" name="ProgramID" value="">
<input type="hidden" name="noMail" value="0"><!-- 0/1 if set to 1, no reply to the visitor is sent. -->
<input type="hidden" name="replyMessage" value="">
<input type="hidden" name="replySubject" value="">
<input type="hidden" name="notifySubject" value="">
<input type="hidden" name="notifyCc" value=""><!-- comma, delimited -->
<input type="hidden" name="notifyBcc" value=""><!-- comma, delimited -->
<!-- These address fields are optional -->
<input type="hidden" name="address" value="">
<input type="hidden" name="city" value="">
<input type="hidden" name="state" value="">
<input type="hidden" name="zip" value="">
<!-- For any additional fields, add the field names separated by a comma to the CommaDelimitedFormFields value. These fields will be saved in the extra notes section -->
<input type="hidden" name="CommaDelimitedFormFields" value="">
<script language=javascript>
<!--
function chkForm(theForm) {
if(theForm.CFirst.value=="") {
alert("Please fill in your first name.");
theForm.CFirst.focus();
return false;
}
if(theForm.CLast.value=="") {
alert("Please fill in your last name.");
theForm.CLast.focus();
return false;
}
var email = theForm.CEmail.value;
if(email.indexOf("@")<1){
alert("Please fill in your email address \n so I may contact you.");
theForm.CEmail.focus();
return false;
}
if(document.all) {
if(theForm.Message.innerText=="") {
alert("Please type a message.");
theForm.Message.focus();
return false;
}
} else {
if(theForm.Message.value=="") {
alert("Please type a message.");
theForm.Message.focus();
return false;
}
}
return true;
}
-->
</script>
<tr>
<td align="right"> First Name</td>
<td>
<input type="text" name="CFirst" size="30" class="CFirst">
<font size="1">*</font>
</td>
</tr>
<tr>
<td align="right"> Last Name</td>
<td>
<input type="text" name="CLast" size="30" class="CLast">
<font size="1">*</font></td>
</tr>
<tr>
<td align="right"> Phone</td>
<td>
<input type="text" name="Phone" size="30" class="Phone">
</td>
</tr>
<tr>
<td align="right"> Fax</td>
<td align="left">
<input type="text" name="Fax" size="30" class="Fax">
</td>
</tr>
<tr>
<td align="right"> Email</td>
<td>
<input type="text" name="CEmail" size="30" class="CEmail">
<font size="1">*</font> </td>
</tr>
<tr>
<td align="right" valign="top"> Message</td>
<td valign="top">
<textarea rows="8" name="Message" id="Message" cols="40"></textarea>
<tr>
<td> </td>
<td align="left" valign="top">
<?php if ( function_exists('wp_nonce_field') )
wp_nonce_field('submit_form', 'submit_form');
?>
<input type="submit" name="Submit" value="Send" id="submit">
</td>
</tr>
</form>
上面的表格将数据保存到外部服务器中,但是现在我也需要将其保存到我的服务器中. 所以我为此使用jQuery. 这是该代码:
The form above saves data into external server, but now I need to save that into my server as well. So i am using jQuery for this. Here is the code for that:
$(function(){
$('#submit').click(function() {
var $nonce = $("input#submit_form").val();
var $first = $("input.CFirst").val();
var $last = $("input.CLast").val();
var $Phone = $("input.Phone").val();
var $Fax = $("input.Fax").val();
var $CEmail = $("input.CEmail").val();
var $message = $("textarea#Message").val();
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if($message != '' && $first !='' && $last!='' && $CEmail!='') {
$.ajax({
url:"../wp-admin/admin-ajax.php",
type:'POST',
data:'action=contact_form&nonce='+$nonce+"&first="+$first+"&last="+$last+"&Phone="+$Phone+"&Fax="+$Fax+"&CEmail="+$CEmail+"&message="+$message,
success: function() {
}
});
}
});
现在,如果我从表单标签中删除操作,它将把条目插入到我的数据库中,但是我不能做,因为我也必须将数据保存到外部服务器中. 谁能知道我们该怎么做?
Now if I remove action from the form tag it will insert entries into my databse but that i cant do as i have to save data into external server as well. Can any one know how we can do this?
谢谢
推荐答案
这是将数据提交到服务器的部分:
This is the part that submits data to the server:
$.ajax({
url:"../wp-admin/admin-ajax.php",
type:'POST',
data:'action=contact_form&nonce='+$nonce+"&first="+$first+"&last="+$last+"&Phone="+$Phone+"&Fax="+$Fax+"&CEmail="+$CEmail+"&message="+$message,
success: function() {
}
});
}
只需调用两次,然后为帖子的接收者设置一个不同的URL:
Just call it twice and set a different URL to the receiver of the post:
$.ajax({
url:"https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
type:'POST',
data:'action=contact_form&nonce='+$nonce+"&first="+$first+"&last="+$last+"&Phone="+$Phone+"&Fax="+$Fax+"&CEmail="+$CEmail+"&message="+$message,
success: function() {
}
});
}
这篇关于我们如何使用一种汇总形式将数据保存在两台服务器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!