Need help with "REST" HTTP POST?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • mobilejack101
    Staff Sergeant

    • Oct 2007
    • 41

    Need help with "REST" HTTP POST?

    Hi all
    To start with I am a total newb and is working hard on my first website.
    www.saloans.net (if you need to look at it)

    I have loaded the ABVFP and it works great....Problem is, I must send my leads via "HTTP POST" to a "database" and not by Email.

    The company I am working with send me a php script to use for posting my leads.I tried to attach the file to this post but it says "invalid file"

    Anyway I was wondering if sombody could help me step by step how to install this script?

    I would like to get an idea how these things work.

    Thanks in advance

    Jaco
    Don't miss the game for fear of striking out...
  • Watdaflip
    Major General

    • Sep 2005
    • 2116

    #2
    Re: Need help with "REST" HTTP POST?

    Post the php code your company sent you and the php code you were using.

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment

    • navaldesign
      General & Forum Moderator

      • Oct 2005
      • 12080

      #3
      Re: Need help with "REST" HTTP POST?

      If i understand correctly, your problem is that you want to BOTH recieve the email AND send the data to the Company's Database. You have two solutions:

      1. Ask them if they can forward you the posted data as email. If yes, the solution is very simple: make the form on your site send the data directly to the company, and they will then email you (automatically) the data.

      2. Your second solution would be to use a script, in addition to ABVFP. based on the curl library. This script, at the end of ABVFP, will send the gathered data as POST to the company's script (and database).

      If on the other hand you don't need an email sent to you, simply use the form they sent you in your page(s). The data will be sent directly to the company's database.
      Navaldesign
      Logger Lite: Low Cost, Customizable, multifeatured Login script
      Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
      DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
      Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

      Comment

      • mobilejack101
        Staff Sergeant

        • Oct 2007
        • 41

        #4
        Re: Need help with "REST" HTTP POST?

        Here is the script I must use.....



        REST Web Service using
        // HTTP POST with curl. PHP4/PHP5
        // Allows retrieval of HTTP status code for error reporting
        // Modified: Johann du Toit, January 7, 2008
        // Original Author: Jason Levitt, February 1, 2006


        error_reporting(E_ALL);


        // The POST URL and parameters
        $request = 'http://rest.affiliateschool.co.za/financeleads/index.php';
        $affiliateid = '999'; // your affiliate id supplied by the affiliate school
        $secret = 'abcdefghijklmnopqrstuvwxyz'; // your secret to authorize submissions. Keep this secret!


        $postargs = 'affiliateid='.$affiliateid.'&secret='.$secret;


        $postargs .= '&loanamount='.urlencode("R8000-****00 Personal Loan"); // The loan amount and type required
        $postargs .= '&credithistory='.urlencode("clean");
        $postargs .= '&loanpurpose='.urlencode("Debt Consolidation");
        $postargs .= '&propertyowned='.urlencode("400000");
        $postargs .= '&bondholder='.urlencode("Standard Bank");
        $postargs .= '&bondoutstanding='.urlencode("100000");
        $postargs .= '&title1='.urlencode("Mr");
        $postargs .= '&dobday1='.urlencode("21");
        $postargs .= '&dobmonth1='.urlencode("Dec"); // Jan, Feb, Mar, etc... not numeric
        $postargs .= '&dobyear1='.urlencode("1971"); // full 4 digit year
        $postargs .= '&firstn1='.urlencode("Test");
        $postargs .= '&lastn1='.urlencode("Test Lead");
        $postargs .= '&maritalstatus='.urlencode("Married");
        $postargs .= '&dependants='.urlencode("2");
        $postargs .= '&phone='.urlencode("012 5431315");
        $postargs .= '&email='.urlencode("test@test.co.za");
        $postargs .= '&alternatephone='.urlencode("083 5551315");
        $postargs .= '&idnumber='.urlencode("7112215018123");
        $postargs .= '&occupation1='.urlencode("Computer Programmer");
        $postargs .= '&employername1='.urlencode("National Bank");
        $postargs .= '&grossincome1='.urlencode("100000");
        $postargs .= '&grossincometype1='.urlencode("Per Year");
        $postargs .= '&joblength1='.urlencode("10");
        $postargs .= '&street='.urlencode("72 Test Street");
        $postargs .= '&suburb='.urlencode("TestVille");
        $postargs .= '&citytown='.urlencode("Testerton");
        $postargs .= '&code='.urlencode("1000");
        $postargs .= '&timeataddress='.urlencode("25");
        $postargs .= '&agreement='.urlencode("Agree"); // Agree or Disagree




        // Get the curl session object
        $session = curl_init($request);


        // Set the POST options.
        curl_setopt ($session, CURLOPT_POST, true);
        curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
        curl_setopt($session, CURLOPT_HEADER, true);
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);


        // Do the POST and then close the session
        $response = curl_exec($session);
        curl_close($session);


        // Get HTTP Status code from the response
        $status_code = array();
        preg_match('/\d\d\d/', $response, $status_code);


        // Check for errors
        switch( $status_code[0] ) {
        case 201:
        // Success
        break;
        case 500:
        die('Your call failed and returned an HTTP status of 500. That means: Service unavailable. An internal problem prevented us from returning data to you.');
        break;
        case 401:
        die('Your call failed and returned an HTTP status of 401. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.');
        break;
        case 400:
        // You may want to fall through here and read the specific XML error
        die('Your call failed and returned an HTTP status of 400. That means: Bad request. The parameters passed to the service did not match as expected.');
        break;
        default:
        die('Your call returned an unexpected HTTP status of:' . $status_code[0]);
        }


        // Output
        echo $response;
        ?></STRONG>

        They said my form outlay should be exactly the same as there's...
        I still need to make a few changes on mine :-p

        If You need to look at it....loanexpress.co.za

        What php file should I paste here? ABVFP has a few and I am not sure witch one.

        Mainly I just need to send a HTTP POST but if AVBFP can send me an email that would be a bonus!

        Thanks for the help !

        Jaco
        Don't miss the game for fear of striking out...

        Comment

        • Watdaflip
          Major General

          • Sep 2005
          • 2116

          #5
          Re: Need help with &quot;REST&quot; HTTP POST?

          Whatever file the action of your form is send to is where you need to add this code.

          I have never used ABVFP, so I also have never seen the files, but it shouldn't effect it if you just paste this code at the bottom of that file before the "?>"

          If there is html code at the bottom add the php code inside a new set of <? ?> at the bottom.

          It should work, but I can't say for sure without knowing what is in the file

          Register/Login Script
          Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #6
            Re: Need help with &quot;REST&quot; HTTP POST?

            It will work ok at the end of ABVFP. However, since you don't want all your forms to send the data to the the script company, you will need to place a if() statement before the code, that will check the form id nr and will only submit for that form.
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment

            • mobilejack101
              Staff Sergeant

              • Oct 2007
              • 41

              #7
              Re: Need help with &quot;REST&quot; HTTP POST?

              Thanks for the help guy's!

              Naval could you give me an example of the "if()" form number? should it look like this ...."(1)" or "if(1)"
              (the number 1 representing the form number)
              and were exactly should I place it in the php code?

              Thanks in advance!

              Jaco
              Don't miss the game for fear of striking out...

              Comment

              • Watdaflip
                Major General

                • Sep 2005
                • 2116

                #8
                Re: Need help with &quot;REST&quot; HTTP POST?

                Heres some code that should work

                First check what the "name" attribute is of your form

                And then just encase the code you are adding with

                if(isset($_POST['name_of_submit_button']))
                {
                // insert code here
                }

                where name_of_submit_button is the name of the submit button I mentioned at the beginning

                Register/Login Script
                Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

                Comment

                • navaldesign
                  General & Forum Moderator

                  • Oct 2005
                  • 12080

                  #9
                  Re: Need help with &quot;REST&quot; HTTP POST?

                  Or, if you actually use ABVFP, since each form has a unique Form id nr, which in the script is $dbts_Formid, the code should be:


                  if($dbts_Formid == "?")
                  {
                  // insert code here
                  }

                  and must be placed before the closing ?> tag
                  Replace ? with the actual Formid used for your form.
                  Navaldesign
                  Logger Lite: Low Cost, Customizable, multifeatured Login script
                  Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                  DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                  Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                  Comment

                  • mobilejack101
                    Staff Sergeant

                    • Oct 2007
                    • 41

                    #10
                    Re: Need help with &quot;REST&quot; HTTP POST?

                    Thank you!

                    Naval I pasted the php code in my "ABVFP/dbts_abvfp.php" folder.
                    Does this mean I have to undo it and paste it in "$dbts_Formid"?

                    Thanks for all the help!

                    You guy's ROCK!
                    Don't miss the game for fear of striking out...

                    Comment

                    • mobilejack101
                      Staff Sergeant

                      • Oct 2007
                      • 41

                      #11
                      Re: Need help with &quot;REST&quot; HTTP POST?

                      I am sorry...that is a stupid question!

                      Should it look like this?

                      if ($dbts_Formid == "1") {
                      // Request LoanExpress.co.za REST Web Service using
                      // HTTP POST with curl. PHP4/PHP5
                      // Allows retrieval of HTTP status code for error reporting
                      // Modified: Johann du Toit, January 7, 2008
                      // Original Author: Jason Levitt, February 1, 2006


                      error_reporting(E_ALL);


                      // The POST URL and parameters
                      $request = 'http://rest.affiliateschool.co.za/financeleads/index.php';
                      $affiliateid = 'xxx'; // your affiliate id supplied by the affiliate school
                      $secret = 'xxxxxxxxxxxxxxxxxxxxxxxxx'; // your secret to authorize submissions. Keep this secret!


                      $postargs = 'affiliateid='.$affiliateid.'&secret='.$secret;


                      $postargs .= '&loanamount='.urlencode("R8000-****00 Personal Loan"); // The loan amount and type required
                      $postargs .= '&credithistory='.urlencode("clean");
                      $postargs .= '&loanpurpose='.urlencode("Debt Consolidation");
                      $postargs .= '&propertyowned='.urlencode("400000");
                      $postargs .= '&bondholder='.urlencode("Standard Bank");
                      $postargs .= '&bondoutstanding='.urlencode("100000");
                      $postargs .= '&title1='.urlencode("Mr");
                      $postargs .= '&dobday1='.urlencode("21");
                      $postargs .= '&dobmonth1='.urlencode("Dec"); // Jan, Feb, Mar, etc... not numeric
                      $postargs .= '&dobyear1='.urlencode("1971"); // full 4 digit year
                      $postargs .= '&firstn1='.urlencode("Test");
                      $postargs .= '&lastn1='.urlencode("Test Lead");
                      $postargs .= '&maritalstatus='.urlencode("Married");
                      $postargs .= '&dependants='.urlencode("2");
                      $postargs .= '&phone='.urlencode("012 5431315");
                      $postargs .= '&email='.urlencode("test@test.co.za");
                      $postargs .= '&alternatephone='.urlencode("083 5551315");
                      $postargs .= '&idnumber='.urlencode("7112215018123");
                      $postargs .= '&occupation1='.urlencode("Computer Programmer");
                      $postargs .= '&employername1='.urlencode("National Bank");
                      $postargs .= '&grossincome1='.urlencode("100000");
                      $postargs .= '&grossincometype1='.urlencode("Per Year");
                      $postargs .= '&joblength1='.urlencode("10");
                      $postargs .= '&street='.urlencode("72 Test Street");
                      $postargs .= '&suburb='.urlencode("TestVille");
                      $postargs .= '&citytown='.urlencode("Testerton");
                      $postargs .= '&code='.urlencode("1000");
                      $postargs .= '&timeataddress='.urlencode("25");
                      $postargs .= '&agreement='.urlencode("Agree"); // Agree or Disagree




                      // Get the curl session object
                      $session = curl_init($request);


                      // Set the POST options.
                      curl_setopt ($session, CURLOPT_POST, true);
                      curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
                      curl_setopt($session, CURLOPT_HEADER, true);
                      curl_setopt($session, CURLOPT_RETURNTRANSFER, true);


                      // Do the POST and then close the session
                      $response = curl_exec($session);
                      curl_close($session);


                      // Get HTTP Status code from the response
                      $status_code = array();
                      preg_match('/\d\d\d/', $response, $status_code);


                      // Check for errors
                      switch( $status_code[0] ) {
                      case 201:
                      // Success
                      break;
                      case 500:
                      die('Your call failed and returned an HTTP status of 500. That means: Service unavailable. An internal problem prevented us from returning data to you.');
                      break;
                      case 401:
                      die('Your call failed and returned an HTTP status of 401. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.');
                      break;
                      case 400:
                      // You may want to fall through here and read the specific XML error
                      die('Your call failed and returned an HTTP status of 400. That means: Bad request. The parameters passed to the service did not match as expected.');
                      break;
                      default:
                      die('Your call returned an unexpected HTTP status of:' . $status_code[0]);
                      }


                      // Output
                      echo $response;

                      $dbts_error = "I cannot process the form. The form has not been correctly setup. !";
                      $_SESSION[error] = $dbts_error ;
                      header("Location: dbts_ABVFP_errorpage.php");
                      }
                      Don't miss the game for fear of striking out...

                      Comment

                      • navaldesign
                        General & Forum Moderator

                        • Oct 2005
                        • 12080

                        #12
                        Re: Need help with &quot;REST&quot; HTTP POST?

                        if ($dbts_Formid == "1") {
                        // Request LoanExpress.co.za REST Web Service using
                        // HTTP POST with curl. PHP4/PHP5
                        // Allows retrieval of HTTP status code for error reporting
                        // Modified: Johann du Toit, January 7, 2008
                        // Original Author: Jason Levitt, February 1, 2006


                        error_reporting(E_ALL);


                        // The POST URL and parameters
                        $request = 'http://rest.affiliateschool.co.za/financeleads/index.php';
                        $affiliateid = 'xxx'; // your affiliate id supplied by the affiliate school
                        $secret = 'xxxxxxxxxxxxxxxxxxxxxxxxx'; // your secret to authorize submissions. Keep this secret!


                        $postargs = 'affiliateid='.$affiliateid.'&secret='.$secret;


                        $postargs .= '&loanamount='.urlencode("R8000-****00 Personal Loan"); // The loan amount and type required
                        $postargs .= '&credithistory='.urlencode("clean");
                        $postargs .= '&loanpurpose='.urlencode("Debt Consolidation");
                        $postargs .= '&propertyowned='.urlencode("400000");
                        $postargs .= '&bondholder='.urlencode("Standard Bank");
                        $postargs .= '&bondoutstanding='.urlencode("100000");
                        $postargs .= '&title1='.urlencode("Mr");
                        $postargs .= '&dobday1='.urlencode("21");
                        $postargs .= '&dobmonth1='.urlencode("Dec"); // Jan, Feb, Mar, etc... not numeric
                        $postargs .= '&dobyear1='.urlencode("1971"); // full 4 digit year
                        $postargs .= '&firstn1='.urlencode("Test");
                        $postargs .= '&lastn1='.urlencode("Test Lead");
                        $postargs .= '&maritalstatus='.urlencode("Married");
                        $postargs .= '&dependants='.urlencode("2");
                        $postargs .= '&phone='.urlencode("012 5431315");
                        $postargs .= '&email='.urlencode("test@test.co.za");
                        $postargs .= '&alternatephone='.urlencode("083 5551315");
                        $postargs .= '&idnumber='.urlencode("7112215018123");
                        $postargs .= '&occupation1='.urlencode("Computer Programmer");
                        $postargs .= '&employername1='.urlencode("National Bank");
                        $postargs .= '&grossincome1='.urlencode("100000");
                        $postargs .= '&grossincometype1='.urlencode("Per Year");
                        $postargs .= '&joblength1='.urlencode("10");
                        $postargs .= '&street='.urlencode("72 Test Street");
                        $postargs .= '&suburb='.urlencode("TestVille");
                        $postargs .= '&citytown='.urlencode("Testerton");
                        $postargs .= '&code='.urlencode("1000");
                        $postargs .= '&timeataddress='.urlencode("25");
                        $postargs .= '&agreement='.urlencode("Agree"); // Agree or Disagree




                        // Get the curl session object
                        $session = curl_init($request);


                        // Set the POST options.
                        curl_setopt ($session, CURLOPT_POST, true);
                        curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
                        curl_setopt($session, CURLOPT_HEADER, true);
                        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);


                        // Do the POST and then close the session
                        $response = curl_exec($session);
                        curl_close($session);


                        // Get HTTP Status code from the response
                        $status_code = array();
                        preg_match('/\d\d\d/', $response, $status_code);


                        // Check for errors
                        switch( $status_code[0] ) {
                        case 201:
                        // Success
                        break;
                        case 500:
                        $dbts_error = "Your call failed and returned an HTTP status of 500. That means: Service unavailable. An internal problem prevented us from returning data to you.";
                        break;
                        case 401:
                        $dbts_error = "Your call failed and returned an HTTP status of 401. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.";
                        break;
                        case 400:
                        // You may want to fall through here and read the specific XML error
                        $dbts_error = "Your call failed and returned an HTTP status of 400. That means: Bad request. The parameters passed to the service did not match as expected.";
                        break;
                        default:
                        $dbts_error = "Your call returned an unexpected HTTP status of:" . $status_code[0]);
                        }

                        if ($dbts_error != ""){

                        $_SESSION[error] = $dbts_error ;
                        header("Location: $errorpage.php");
                        }
                        }



                        Paste the code JUST BEFORE this line:

                        header("Location: $returnpage");

                        However, i don't think that this will work. You see, as your script is presented here, it posts directly the values in parenthesis:

                        $postargs .= '&loanamount='.urlencode("R8000-****00 Personal Loan");

                        whilst in reality the values are recieved from the form, so it should be something like:

                        $postargs .= '&loanamount='.urlencode($_POST['loanamount']);

                        and similar for the other fields. The part in red inside the square brackets should be the field names as you have used them in your form.
                        Navaldesign
                        Logger Lite: Low Cost, Customizable, multifeatured Login script
                        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                        Comment

                        • mobilejack101
                          Staff Sergeant

                          • Oct 2007
                          • 41

                          #13
                          Re: Need help with &quot;REST&quot; HTTP POST?

                          That is my problem..I need to change my form to work with the php code.

                          I can not change the php code otherwise it wont work with the database as I understand.

                          That is why I started the new tread on howto change the html on my form.

                          SUMMERY:

                          I need to get my form to run with this php script without changing the script.

                          How do I change my form so that it maches the script and works?

                          Thank you for your help !

                          Jaco
                          Don't miss the game for fear of striking out...

                          Comment

                          • mobilejack101
                            Staff Sergeant

                            • Oct 2007
                            • 41

                            #14
                            Re: Need help with &quot;REST&quot; HTTP POST?

                            Hi Naval

                            I pasted the html like you said at..



                            Will the PHP script work with my form now or should I make more changes?

                            Thanks in advance!

                            Jaco
                            Don't miss the game for fear of striking out...

                            Comment

                            • navaldesign
                              General & Forum Moderator

                              • Oct 2005
                              • 12080

                              #15
                              Re: Need help with &quot;REST&quot; HTTP POST?

                              As i said, your own code, needs the values from the form. So, you need ALL the lines like

                              $postargs .= '&loanamount='.urlencode("R8000-****00 Personal Loan");

                              to be changed to something like

                              $postargs .= '&loanamount='.urlencode($_POST['loanamount']);


                              where loanamount (and all others, in the rest of your code) have to be the NAMES of your form fields.

                              Otherwise it will not work, as it will always submit the sane values (the ones in the example code).

                              To clarify: your code MUST be changed because, right now, it submits to the database the values that are inside the double quotes ("R8000 - ****00 Personal Loan") and NOT the real values that the users submit. Please understand that this is an EXAMPLE code provided by them, to put you in the right way, but NOT the actual code to use.
                              Navaldesign
                              Logger Lite: Low Cost, Customizable, multifeatured Login script
                              Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                              DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                              Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                              Comment

                              Working...
                              X