Question

Quel est le meilleur / moyen le plus facile d'envoyer des informations à partir d'un formulaire à deux endroits différents, ont essentiellement 2 actions sur une forme. J'ai quelques domaines qui doivent être nommés différemment pour chaque action, par exemple ..

<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>

regard post.php comme celui-ci.

<?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>

comme vous pouvez le voir, j'ai essayé d'utiliser ajax .. mais je suppose que je fais quelque chose de mal, si vous avez des suggestions pour ce faire d'une autre façon, ce serait génial!] Merci

Était-ce utile?

La solution

Vous pourriez le faire côté serveur avec plissement post.php.

Alors, vous avez défini vos variables et ils ont été validées et nettoyées, puis:

$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);

faudrait peut-être changé un peu pour faire exactement ce que vous voulez, et aurait probablement besoin de forger les en-têtes comme il est un navigateur de le faire, mais qui est la fonctionnalité de base de celui-ci. Pourrait aussi besoin de mettre CURLOPT_RETURNTRANSFER à true.

Autres conseils

l'envoi de requêtes XHR ou Ajax n'est pas autorisé interdomaine. Vous pouvez y parvenir en utilisant cURL. J'imagine qu'il ya assez peu de tutoriels sur la présentation des formulaires en utilisant PHP et cURL flottant ici.

échantillon recherche google pour vous mettre dans la bonne direction: http://www.google.com/search?q=using+curl+to+submit+form+data+php

Votre principal problème est que le javascript ne peut pas être utilisé pour accéder à des fichiers sur d'autres serveurs comme vous essayez de le faire. Une approche qui fonctionnerait serait d'avoir des fichiers PHP sur votre serveur qui se forme juste mis en place et les poster (via des formulaires submit()ted avec javascript) aux serveurs distants.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top