Example source code for PHP Post Method call to Creator Form (from PHP Command Line) - seems to work.

Example source code for PHP Post Method call to Creator Form (from PHP Command Line) - seems to work.

Hey all, after some happy hacking...I appear to have been able to get this working from a command line call like this...

C:\PHP_TESTS>php testcalltoZohoCreatorForm.php

...the PHP seems to work OK whether from a Windows (XAMPP PHP) or Linux environment.

Being able to do this is useful if, say, you ever need to schedule some activity, such as a nightly or hourly data transfer from one server to another.

Thanks to some other forum posts, I was able to get this working from a HTML form (i.e. webpage)...and I was able to use this knowledge to have a crack at the command line version...this forum post is here...

http://help.zoho.com/portal/en/community/topic/need-help-with-zoho-creator-api#2266000001962402

I also should say thanks to Well House Consultants whose article here (http://www.wellho.net/resources/ex.php4?item=h112/dopost.php) gave me the code on which to base this attempt.

This also solve my other post - http://help.zoho.com/portal/en/community/topic/php-calls-to-creator-forms-using-post-method-via-php-cli-almost-there-please-help-me-over-the-line

Hope this is helpful to someone else...I always felt the Zoho documentation could have included something like this.

  1. <?php

  2. //
  3. // This generic function does the 'hard work' of opening sockets
  4. // and packing the POST array
  5. //

  6. function postit($host, $url, $postdata) {
  7. $fp = pfsockopen ( $host, 80, &$errno, &$errstr, 60 );
  8. if( ! $fp ) return "$errstr ($errno)\n";
  9. fputs ($fp,"POST $url HTTP/1.1\n");
  10. fputs ($fp,"Host: $host\n");
  11. fputs ($fp,"User-Agent: Autopost demonstration script\n");
  12. fputs ($fp,"Accept: */*\n");
  13. fputs ($fp,"Content-type: application/x-www-form-urlencoded\n");
  14. fputs ($fp,"Content-length: ".strlen($postdata)."\n\n");
  15. fputs ($fp,"$postdata\n\n");
  16. $output = "";
  17. while( !feof( $fp ) ) {
  18. $output .= fgets( $fp, 1024);
  19. }
  20. fclose ( $fp);
  21. return ($output);
  22. }

  23. $xmlstringdata = "<ZohoCreator><applicationlist><application name=\"sfit-email-templates\"><formlist><form name=\"Post_Method_Receiver_Test\"><add><field name=\"Task\"><value>liamsTestFROMPHPCLI</value></field><field name=\"Description\"><value>liamsTestDescrFROMPHPCLI</value></field></add></form></formlist></application></applicationlist></ZohoCreator>";

  24. $host = "creator.zoho.com";
  25. $url = "/api/xml/write/apikey=95653c2e0ae139f785a81arf4bdc44a3&ticket=87b35c49122344c6059a132347266e7112";
  26. $postdata = "XMLString=$xmlstringdata&zc_ownername=liamzoho2";
  27.         $gotten = postit($host, $url, $postdata);

  28. # You'll get back all the headers, a blank line and then
  29. # the content ....  this test displays it for all to see!

  30. $real = htmlspecialchars($gotten);
  31. $sayurl = "http://$host$url";

  32. echo "In an echo statement now - $real";
  33. echo "In an echo statement now - $sayurl";
  34. echo "In an echo statement now - $postdata";

  35. ?>