Frage

Was ist der beste/einfachste Weg, um Informationen aus einem Formular an zwei verschiedene Orte zu senden, im Grunde genommen 2 Aktionen auf einem Formular. Ich habe ein paar Felder, die beispielsweise für jede Aktion anders benannt werden müssen.

<form id="form" name="form" action='post.php' method='POST' accept-charset='UTF-8'><input type='hidden' name='xnQsjsdp' value=SlGqwqH3ITc$/>  <input type='hidden' name='xmIwtLD' value=x4LHs39QfKiFkCs1PrsnsG-*B6-MHnNR/>  <input type='hidden' name='actionType' value=TGVhZHM=/> <input type='hidden' name='returnURL' />
<input name='firstName' type='text' id="firstName" style="float:left; width:45%;" maxlength='40' />
<input name='lastName' type='text' id="lastName" style="float:left; width:45%;" maxlength='40' />
<input type="submit" />
</form>

Post.php sieht so aus.

<?php

    if ($_SERVER['REQUEST_METHOD'] == "POST") {

      $hidden1      = $_POST["xnQsjsdp"];
      $hidden2      = $_POST["xmIwtLD"];
      $hidden3      = $_POST["actionType"];
      $hidden4      = $_POST["returnURL"];
      $firstName    = $_POST["firstName"];
      $lastName     = $_POST["lastName"];
      $street       = $_POST["Street"];
      $city         = $_POST["City"];
      $State        = $_POST["State"];
      $zipCode      = $_POST["Zip"];
      $email        = $_POST["Email"];
      $phone        = $_POST["Phone"];
      $LEADCF7      = $_POST["LEADCF7"];
      $zohoPrams    = "xnQsjsdp=$hidden1&xmIwtLD=$hidden2&actionType=$hidden3&returnURL=$hidden4&First Name=$firstName&Last Name=$lastName";
      $maxPrams     = "FName=$firstName&LName=$lastName";

    };

?>
<script>
$(function() { // setup an onReady (similar to onLoad) handler
        $.post("https://crm.zoho.com/crm/WebToLeadForm", <?php echo $zohoPrams; ?>; // post to first address
        $.post("http://www.max360group.com/", <?php echo $maxPrams; ?>; // post to second address
});
</script>

Wie Sie sehen, habe ich versucht, AJAX zu verwenden. Aber ich denke, ich mache etwas falsch, wenn Sie Vorschläge haben, dies auf andere Weise zu tun, wäre das großartig:] Danke!

War es hilfreich?

Lösung

Sie können es Server mit curl in post.php machen.

Sie haben also Ihre Variablen festgelegt und sie wurden validiert und gereinigt, dann:

$zoho = curl_init("https://crm.zoho.com/crm/WebToLeadForm");
curl_setopt($zoho, CURLOPT_SSL_VERIFYPEER, false); //Note, not very secure.  Would have to get certificate otherwise.  Look up how to.
curl_setopt($zoho, CURLOPT_FOLLOWLOCATION, 1); //Makes sure that it follows any redirects
curl_setopt($zoho, CURLOPT_RETURNTRANSFER, 1); //Returns the result instead of outputting it to the browser
curl_setopt($zoho, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); //Will make the end server think it was submitted with Firefox, and not by a server using cURL.
curl_setopt($zoho, CURLOPT_POST, 1);
curl_setopt($zoho, CURLOPT_POSTFIELDS, $zohoprams);  
//If you want the rest of the $_POST data and not just what you set above in $zohoprams, 
//CURLOPT_POSTFIELDS takes either an array, which will automatically do the appropriate thing with it as a $key=$value, or a string like you have formatted for $zohoprams
curl_exec($zoho);
curl_close($zoho);

$max = curl_init('http://www.max360group.com/');
curl_setopt($max, CURLOPT_POST, 1);
curl_setopt($max, CURLOPT_POSTFIELDS, $maxprams);
curl_setopt($max, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($max, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($max, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_exec($max);
curl_close($max);

Möglicherweise muss ein wenig geändert werden, um genau das zu tun, was Sie wollen, und müsste wahrscheinlich die Header so schmieden, als wäre es ein Browser, aber das ist die grundlegende Funktionalität davon. Möglicherweise muss auch curlopt_returntransfer auf true festgelegt werden.

Andere Tipps

Das Senden von XHR- oder AJAX -Anfragen ist nicht zulässig. Sie können dies mit Curl erreichen. Ich würde mir vorstellen, dass es einige Tutorials über die Einreichung von Formularen mit PHP und Locken gibt, die hier herumschweben.

Beispiel Google Search, um Sie in die richtige Richtung zu bringen: http://www.google.com/search?q=using+curl+To+Submit+Form+Data+Php

Ihr Hauptproblem ist, dass JavaScript nicht zum Zugriff auf Dateien auf anderen Servern verwendet werden kann, wie Sie es versuchen möchten. Ein Ansatz, der funktionieren würde submit()mit JavaScript) an die Remote -Server.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top