2011-05-03 43 views
0

我正在使用第三方工具。這裏是表格:如何使用一個提交表單將數據保存在兩臺服務器上?

<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。 下面是該代碼:

$(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-\.][email protected]([\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() { 
      } 
     }); 
    } 
}); 

現在,如果我刪除從表單標籤的行動,它將插入條目到我DATABSE但我不能這樣做,因爲我有保存數據到外部服務器上。 任何人都可以知道我們如何做到這一點?

感謝

+0

請妥善格式化你的代碼中使用編輯器中的「代碼」按鈕。 – ThiefMaster 2011-05-03 11:30:58

+0

請檢查現在... – Naveen 2011-05-03 11:35:42

回答

1

這是提交數據到服務器的部分:

    $.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設置後的接收器:

    $.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() { 

           } 
          }); 
        } 
+0

也許最好是以兩個單獨的表單包含字段,然後提交適當的表單。 – Kon 2011-05-03 13:16:30

1

首先,$ -prefix JS瓦爾除非他們是jQuery的對象。 .val()返回純字符串(或某些字段的數組)。

然後,解決你的問題,你需要提交表格,然後再使用AJAX您的服務器,當請求完成後(即在成功回調),提交表單到外部服務器,您需要在表格的action中指定。

+0

你能舉個例子嗎?所以我可以更好地理解 – Naveen 2011-05-03 11:32:37

相關問題