Results 1 to 28 of 28

Thread: Need help with "REST" HTTP POST?
      
   

  1. #1
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Exclamation 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

  2. #2
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default 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

  3. #3
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

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


  4. #4
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Question 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

  5. #5
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default Re: Need help with "REST" 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

  6. #6
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Need help with "REST" 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!


  7. #7
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" 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

  8. #8
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default Re: Need help with "REST" 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

  9. #9
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Need help with "REST" 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!


  10. #10
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" 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!

  11. #11
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" 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");
    }

  12. #12
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Need help with "REST" 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!


  13. #13
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" 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

  14. #14
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" HTTP POST?

    Hi Naval

    I pasted the html like you said at..

    http://www.vodahost.com/vodatalk/for...html-code.html

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

    Thanks in advance!

    Jaco

  15. #15
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Need help with "REST" 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!


  16. #16
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" HTTP POST?

    Naval I cant find the line...

    "Paste the code JUST BEFORE this line:"

    header("Location: $returnpage");


    The only place I can find the line is in the code you posted.

    I dont see it in my "ABVFP/dbts_abvfp.php" folder or in the "submit leads" PHP code?

    Am I missing something here?

    Please help!

    Jaco

  17. #17
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Need help with "REST" HTTP POST?

    You need to open the dbts_abvfp.php file that you can find in the ABVFP zip. Then you need to edit it as suggested above, and last, you need to upload the edited file into your site ABVFP folder (replacing the existing one).
    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!


  18. #18
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" HTTP POST?

    Thanks

    Sorry its hard for me as a novice to always understand what you mean..

    Hope fully I will get it right soon!

    Some times I want to slice my wrists with a wet Marri biscuits LOL!

    I will get back to you...

    Thank you for your understanding and time!

    Jaco

  19. #19
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" HTTP POST?

    Naval if I change those lines....
    from.....

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

    to.......

    "$postargs .= '&loanamount='.urlencode($_POST['loanamount']); "
    my loanamount droplist name is "Loan_Amount-R[]"

    How will it look after the change?

    Can I use the capital letters? Underscores? The "-" and the "R" and the "[]"?

    I am not sure what is alowed and what not...

    Please help!

    Jaco

  20. #20
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Need help with "REST" HTTP POST?

    Make it

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

    Do NOT add the [] and eliminate also from your form, the load amount and type can NOT be a multiple choice listbox, only one choice is allowed....
    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!


  21. #21
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" HTTP POST?

    This is what the code looks like now....

    When I click submit, I get a error message...

    Parse error: syntax error, unexpected '}' in /home/gcumjcjh/public_html/ABVFP/dbts_abvfp.php on line 37

    What is wrong?

    Help please!



    <?php
    # ----------------------------------------------------
    # -----
    # ----- This script was created by DB Technosystems.com
    # -----
    # ----- http://www.dbtechnosystems.com
    # -----
    # ----------------------------------------------------

    error_reporting(55);
    session_start();
    //--- For debugging purposes only----
    //echo "Opened file abvfp.php";
    //exit;
    //putenv("TZ=Europe/Rome"); // Change to whatever yout timezone is
    require ("dbts_ABVFP_config.php");

    //--- For debugging purposes only----
    //echo "Opened config file abvfp.php";
    //exit;
    $dbts_Formid = $_POST['Formid'];
    //--- For debugging purposes only----
    //echo "dbts_Formid = testing $dbts_Formid testing";
    //exit;
    $dbts_Formurl1 = $_SERVER['HTTP_REFERER'];
    //--- For debugging purposes only----
    if ($dbts_Formid == "") {
    $dbts_error = "I cannot process the form. The form has not been correctly setup. !";
    $_SESSION[error] = $dbts_error ;
    header("Location: dbts_ABVFP_errorpage.php");
    }
    $db = mysql_connect($db_host, $db_user, $db_password);
    if ($db == FALSE){
    $dbts_error = "Could not connect to the Database Server. Please check user details !";
    $_SESSION[error] = $dbts_error ;
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    mysql_select_db($db_name, $db);
    if (!mysql_select_db($db_name, $db)) {
    $dbts_error = "Could not select Database. Please check user details !";
    $_SESSION[error] = $dbts_error ;
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    }
    $query = "SELECT Formid, Formname, Site, Formurl, Max_filesize, Uploadfolder, Emailaddress, EmailSubject, Emailheader, Emailfooter, Thankyoupage, Errorpage, Autoresponder, Include_email, Autoresponder_EmailSubject, Autoresponder_From, Autoresponder_Emailheader, Autoresponder_Emailfooter, Database_Store FROM ABVFP_Forms WHERE Formid= '$dbts_Formid'";
    $result = mysql_query($query, $db);
    $row = mysql_fetch_array($result, MYSQL_ASSOC);
    if ($row =="") {
    $dbts_error = "I cannot process the form. The form has not been correctly setup. !";
    $_SESSION[error] = $dbts_error ;
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    }
    //mysql_close($db);
    //--- For debugging purposes only----
    //echo "Finished connecting to the DB";
    //exit;
    // -------- RECEIVIMG CONFIGURATION VARIABLES FROM THE DB -----------

    $ndsite = $row[Site] ;
    $ndformurl = $row[Formurl] ;
    $ndfilesize = $row[Max_filesize] ;
    $ndmailsubject = $row[EmailSubject] ;
    $ndmailfirstline = $row[Emailheader] ;
    $ndmaillastline = $row[Emailfooter] ;
    $autoresponderfirstline = $row[Autoresponder_Emailheader] ;
    $autoresponderlastline = $row[Autoresponder_Emailfooter] ;
    $autoresponder = $row[Autoresponder] ;
    $autoresponderfrom = $row[Autoresponder_From] ;
    $autorespondersubject = $row[Autoresponder_EmailSubject] ;
    $nduploadfolder = $row[Uploadfolder] ;
    $returnpage = $row[Thankyoupage] ;
    $errorpage = $row[Errorpage] ;
    $ndmailaddress = $row[Emailaddress] ;
    $ndincludeemail = $row[Include_email] ;
    $ndDatabase_Store = $row[Database_Store] ;
    //Finding out if there are more than email addresses to receive the email

    $ndmailaddress1 = explode(",", $ndmailaddress);
    //Setting the autoresponder "From" email address
    if (count($ndmailaddress1 ==0))
    {
    $ndmailaddress2 = $ndmailaddress;
    }
    if (count($ndmailaddress1 >=1)) {
    $ndmailaddress2 = $ndmailaddress1[0];
    }
    if ($ndformurl1 != "") {
    if ($ndformurl1 != $ndformurl) {
    $nderror = "Illegal Form Submission \n";
    }
    }
    //--- For debugging purposes only----
    //echo "Finished field examining";
    //exit;
    // -------- RECEIVIMG FIELDNAMES VALUES AND VALIDATION DETAILS------

    $internalfields = array ("submit", "reset", "Formid", "Submit", "SUBMIT", "RESET", "Reset");
    $i = "0";
    reset ($HTTP_POST_VARS);
    while (list ($key, $val) = each ($HTTP_POST_VARS)) {
    if (!in_array($key, $internalfields)) {
    $fieldname = trim($key);
    $fieldlenght = strlen(trim($key));
    $realfieldlength = $fieldlenght;
    if (substr($fieldname, -3, 1) == "-") {
    $ndLast = substr($fieldname, -1, 1);
    if ($ndLast == "R") {
    $R[$i] = "R";
    $V[$i] = substr($fieldname, -2, 1);
    } else {
    $V[$i] = substr($fieldname, -1, 1);
    $R[$i] = substr($fieldname, -2, 1);
    }
    $realfieldlength = $fieldlenght-3;
    }
    if (substr($fieldname, -2, 1) == "-") {
    $ndLast = substr($fieldname, -1, 1);
    if ($ndLast == "R") {
    $R[$i] = "R";
    } else {
    $V[$i] = substr($fieldname, -1, 1);
    }
    $realfieldlength = $fieldlenght-2;
    }

    // ------ Checking for miltiple Choice Values ---------
    @$fieldvalue = $_POST[$key];
    if (is_array($fieldvalue)) {
    @$fieldvalue = @implode(", ",$_POST[$key]);
    }
    // ----Setting the clear Field Names and Values-------
    $fieldname = substr($key, 0, $realfieldlength);
    if ($fieldname == "Email")
    {
    $ndemail = $fieldvalue;
    }
    $ndfieldname[] = $fieldname;
    $ndfieldname_final[] = str_replace("_", " ", $fieldname);
    $ndfieldvalue[] = $fieldvalue;
    $i = $i + 1 ;
    }
    }

    //--- For debugging purposes only----
    //echo "Finished field examining";
    //exit;
    // ------RECEIVING FILE VARIABLES--------------------

    reset ($_FILES);
    $i = 0;
    while (list ($key, $val) = each ($_FILES)) {
    if ($_FILES[$key]['name']!="") {
    $upload_Name1 = ($_FILES[$key]['name']);
    $upload_Name[] = str_replace(" ", "_", $upload_Name1);
    $upload_Size[] = ($_FILES[$key]['size']);
    $upload_Temp[] = ($_FILES[$key]['tmp_name']);
    $upload_Type[] = ($_FILES[$key]['type']);
    $uploadlink[] = "$nduploadfolder/$upload_Name[$i] \n";
    $ndfieldname[] = $key;
    $ndfieldname_final[] = str_replace("_", " ", $key);
    $ndfieldvalue[] = $uploadlink[$i];
    // if the upload succeded, the file will exist
    if (file_exists($upload_Temp[$i])){
    // check to make sure that it is an uploaded file and not a system file
    if(is_uploaded_file($upload_Temp[$i])){
    // open the file for a binary read
    $file = fopen($upload_Temp[$i],'rb');
    // read the file content into a variable
    $data1 = fread($file,filesize($upload_Temp[$i]));
    // close the file
    fclose($file);
    // now we encode it and split it into acceptable length lines
    $data[] = chunk_split(base64_encode($data1));
    }
    $i = $i + 1;
    }
    }
    }

    function RecursiveMkdir($path)
    {
    if (!file_exists($path)) {
    RecursiveMkdir(dirname($path));
    mkdir($path, 0777);
    }
    }
    //--- For debugging purposes only----
    //echo "Finished uploading attached files ";
    //exit;

    // ------------VALIDATION OF THE FIELDS----------------
    // ------------CHECKING FOR REQUIRED FIELDS----------
    $i = 0;
    for ($i = 0; $i < count($ndfieldname); $i++) {
    if ($R[$i] == "R") {
    if (strlen($ndfieldvalue[$i]) == 0) {
    $nderror .= "The field $ndfieldname[$i] is missing !\n";
    }
    }

    // ------------CHECKING FOR CORRECT EMAIL FIELDS----------

    if ($V[$i] == "e") {
    $fieldtype[$i] = "VARCHAR (100)" ;
    if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $ndfieldvalue[$i])) {
    $nderror .= "Your Email seems incorrect !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    // ------------CHECKING FOR NUMERIC FIELDS----------

    if ($V[$i] == "N") {
    $fieldtype[$i] = "INT" ;
    if ($ndfieldvalue[$i] != "") {
    if (!is_numeric($ndfieldvalue[$i])) {
    $nderror .= "The field $ndfieldname[$i] should be only numbers / No spaces allowed $nerror !\n";
    }
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 30 WITHOUT EMAIL ----------
    if ($V[$i] == "A") {
    $fieldtype[$i] = "VARCHAR (30)" ;
    if (strlen($ndfieldvalue[$i]) >= 30) {
    $nderror .= "The field $ndfieldname[$i] must be less than 30 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 60 WITHOUT EMAIL ----------
    if ($V[$i] == "B") {
    $fieldtype[$i] = "VARCHAR (60)" ;
    if (strlen($ndfieldvalue[$i]) >= 60) {
    $nderror .= "The field $ndfieldname[$i] must be less than 60 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 200 WITHOUT EMAIL ----------
    if ($V[$i] == "C") {
    $fieldtype[$i] = "VARCHAR (250)" ;
    if (strlen($ndfieldvalue[$i]) >= 200) {
    $nderror .= "The field $ndfieldname[$i] must be less than 200 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }

    // ------------CHECKING FOR FIELD SIZE UP TO 500 WITHOUT EMAIL ----------

    if ($V[$i] == "D") {
    $fieldtype[$i] = "MEDIUMTEXT" ;
    if (strlen($ndfieldvalue[$i]) >= 500) {
    $nderror .= "The field $ndfieldname[$i] must be less than 500 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }
    // ------------CHECKING FOR UNLIMITED FIELD SIZE WITHOUT EMAIL ----------
    if ($V[$i] == "E") {
    $fieldtype[$i] = "TEXT" ;
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 30 WITH ONE EMAIL ----------
    if ($V[$i] == "F") {
    $fieldtype[$i] = "VARCHAR (30)" ;
    if (strlen($ndfieldvalue[$i]) >= 30) {
    $nderror .= "The field $ndfieldname[$i] must be less than 30 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }

    // ------------CHECKING FOR FIELD SIZE UP TO 60 WITH ONE EMAIL ----------
    if ($V[$i] == "G") {
    $fieldtype[$i] = "VARCHAR (60)" ;
    if (strlen($ndfieldvalue[$i]) >= 60) {
    $nderror .= "The field $ndfieldname[$i] must be less than 60 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 200 WITH ONE EMAIL ----------
    if ($V[$i] == "H") {
    $fieldtype[$i] = "VARCHAR (250)" ;
    if (strlen($ndfieldvalue[$i]) >= 200) {
    $nderror .= "The field $ndfieldname[$i] must be less than 200 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 500 WITH ONE EMAIL ----------
    if ($V[$i] == "J") {
    $fieldtype[$i] = "TEXT" ;
    if (strlen($ndfieldvalue[$i]) >= 500) {
    $nderror .= "The field $ndfieldname[$i] must be less than 500 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    // ------------CHECKING FOR UNLIMITED FIELD SIZE WITH ONE EMAIL ----------
    if ($V[$i] == "I") {
    $fieldtype[$i] = "TEXT" ;
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    if ($V[$i] == "") {
    $fieldtype[$i] = "VARCHAR (250)";
    }
    }
    // ------------CHECKING FOR MAX UPLOADED FILE SIZE ----------------------
    $ndfilesize1= $ndfilesize*1024;
    for ($i = 0; $i < count($upload_Name); $i++) {
    if ($upload_Name[$i] != "" ) {
    if ($upload_Size[$i] >= $ndfilesize1) {
    $nderror .= "The size of $upload_Name[$i] is bigger than the allowed $ndfilesize Kb !\n";
    }
    }

    }
    if ($nderror != "") {
    $_SESSION[error] = $nderror ;
    header("Location: $errorpage");
    exit;
    }
    //--- For debugging purposes only----
    //echo "Finished validation of the fields ";
    //exit;


    //--------- Move the files to destination----------------
    $nduploadfolder1 = basename($nduploadfolder);
    for ($i = 0; $i < count($upload_Name); $i++) {
    if ($upload_Size[$i] < $ndfilesize1 and $upload_Size[$i] >0)
    {
    $uploadFile = "$nduploadfolder1/".$upload_Name[$i];
    if (!is_dir(dirname($uploadFile)))
    {
    @RecursiveMkdir(dirname($uploadFile));
    }
    else
    {
    @chmod(dirname($uploadFile), 0777);
    }
    @move_uploaded_file( $upload_Temp[$i] , $uploadFile);
    chmod($uploadFile, 0644);
    }
    }
    //--- For debugging purposes only----
    //echo "Finished uploading files ";
    //exit;
    //------------- Find Server date and Time--------------------
    $date = date("l jS F Y, g:i A");
    $Submission_Date = date("F/d/Y");
    //----------------- Find Browser and IPaddress --------------
    $browser =$_SERVER['HTTP_USER_AGENT'];
    $ip = $_SERVER['REMOTE_ADDR'];


    // ---- STORING FIELD VALUES IN THE DATABASE TABLE ---------------
    if ($ndDatabase_Store == "Yes") {
    $dbts_table = "Form_Nr_$dbts_Formid";
    // Check if the table exists already ------------

    $result = mysql_list_tables($db_name);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    $key= "Tables_in_$db_name";
    $tablename[] = $row[$key];
    }
    //--- For debugging purposes only----
    //print_r($tablename);
    //exit;
    if (!in_array($dbts_table, $tablename)) {
    $query = "CREATE TABLE `$dbts_table` (";
    $query .='`Record_Nr` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ';
    for ($i = 0; $i < (count($ndfieldname) - count($upload_Name)); $i++) {
    //$ndmailbody .= "$ndfieldname[$i] = $ndfieldvalue[$i] \r\n";
    $query .= "`$ndfieldname[$i]` $fieldtype[$i], ";
    }
    $query .='`Submission_Date` VARCHAR (20),';
    $query .='`IP_Address` VARCHAR (15)';
    $query .=' )'
    . ' ENGINE = myisam;';
    }
    //--- For debugging purposes only----
    //echo "Query = $query****";
    //exit;
    if (mysql_query($query, $db)){
    $message = "Installation completed";
    }
    else {
    $_SESSION[error] = "There has been an unknown error during Form Table creation. Invalid Query = $query: Please contact support at ???? @ dbtechnosystems.com";
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    //--- For debugging purposes only----
    //echo "Finished creating table ";
    //exit;
    // Check if the field exists in the table, to avoid crashes
    $result = mysql_list_fields($db_name, $dbts_table, $db);
    $fieldnumber = mysql_num_fields($result);
    for ($i = 0; $i < $fieldnumber; $i++) {
    $fieldstable[$i] = mysql_field_name($result, $i);
    }

    @$query = "INSERT INTO `$dbts_table`(";
    for ($i = 0; $i < (count($ndfieldname) - count($upload_Name)); $i++) {
    $dbfield = $ndfieldname[$i];
    //$dbvalue = $ndfieldvalue[$i];
    if (in_array($ndfieldname[$i],$fieldstable)) {
    @$query .= "`$ndfieldname[$i]` ,";
    }
    }
    @$query .= "`Submission_Date` ,";
    @$query .= "`IP_Address` ";
    @$query .= ")";

    @$query .= "VALUES (";
    for ($i = 0; $i < (count($ndfieldname) - count($upload_Name)); $i++) {
    if (in_array($ndfieldname[$i],$fieldstable)) {
    @$query .= "\"$ndfieldvalue[$i]\",";
    }
    }
    @$query .= "\"$Submission_Date\",";
    @$query .= "\"$ip\"";
    @$query .= ")" ;
    //echo $pfw_strQuery; Only for debugging
    $db = mysql_connect($db_host, $db_user, $db_password);
    if (!$db) {
    $_SESSION[error] = "There has been a connection problem:". mysql_error()."Please contact support at info @ dbtechnosystems.com";
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    $db_selected = mysql_select_db($db_name, $db);
    if (!$db_selected) {
    $_SESSION[error] = "There has been a connection problem:". mysql_error().". Please contact support at ???? @ dbtechnosystems.com";
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    //insert new record
    $result = mysql_query($query);
    if (!$result) {
    $_SESSION[error] = "There has been a connection problem:". mysql_error().". Please contact support at info @ dbtechnosystems.com";
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    mysql_close($db);
    }

    // ------------Building the mail ----------------------

    // generate a random string to be used as the boundary marker
    $mime_boundary="==Multipart_Boundary_x".md5(mt_ran d())."x";
    // now we'll build the message headers
    $ndmailhead = "From: $ndemail\r\n" .
    "MIME-Version: 1.0\r\n" .
    "Content-Type: multipart/mixed;\r\n" .
    " boundary=\"{$mime_boundary}\"";

    for ($i = 0; $i < count($ndfieldname); $i++) {
    $ndmailbody .= "$ndfieldname_final[$i] = ".stripslashes($ndfieldvalue[$i])." \r\n";
    }
    $ndmailbody1 .= "$ndmailfirstline \r\n"
    . "$ndmailbody \r\n"
    . "$ndmaillastline \r\n"
    . "-----------------------------------------------------------\n"
    . "Date of submission : $date\r\n"
    . "Browser : $browser\r\n"
    . "IP address : $ip\r\n";

    $ndmailbody1 = "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $ndmailbody1 . "\n\n";
    // now we'll process our uploaded files
    if (count($upload_Name)>0) {
    for ($i = 0; $i < count($upload_Name); $i++){
    // now we'll insert a boundary to indicate we're starting the attachment
    // we have to specify the content type, file name, and disposition as
    // an attachment, then add the file content.
    // NOTE: we don't set another boundary to indicate that the end of the
    // file has been reached here. we only want one boundary between each file
    // we'll add the final one after the loop finishes.

    $type = $upload_Type[$i];
    $name = $upload_Name[$i];
    $ndmailbody1 .= "--{$mime_boundary}\n" .
    "Content-Type: {$type};\n" .
    " name=\"{$name}\"\n" .
    "Content-Disposition: attachment;\n" .
    " filename=\"{$fileatt_name}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $data[$i] . "\n\n";
    }
    }
    // here's our closing mime boundary that indicates the last of the message
    $ndmailbody1.="--{$mime_boundary}--\n";

    for ($i = 0; $i <= count($ndmailaddress1); $i++){
    mail($ndmailaddress1[$i], $ndmailsubject, $ndmailbody1, $ndmailhead);
    }
    if ($autoresponder == "Yes")
    {
    if ($ndincludeemail = "Yes") {
    $ndmfromaddress = $ndmailaddress2;
    }
    $ndmailbody = "";
    for ($i = 0; $i < (count($ndfieldname) - count($upload_Name)); $i++) {
    $ndmailbody .= "$ndfieldname_final[$i] = ".stripslashes($ndfieldvalue[$i])." \r\n";
    }
    if (count($upload_Name)>0) {
    $ndmailbody .= "You have also uploaded the following files: \r\n";
    for ($i = 0; $i < count($upload_Name); $i++){
    $k = $i +1;
    $ndmailbody .= "File $k : $upload_Name[$i] \r\n" ;
    }
    }
    $ndmailsubject = $autorespondersubject;
    $ndmailhead = "MIME-Version: 1.0\r\n";
    $ndmailhead .= "From: $autoresponderfrom < $ndmfromaddress >" . "\r\n";
    $ndmailbody1 = "$autoresponderfirstline\n"
    . "$ndmailbody\r\n"
    . "$autoresponderlastline\r\n"
    . "-----------------------------------------------------------\r\n"
    . "Time of submission : $date\r\n"
    . "-----------------------------------------------------------\r\n";
    mail($ndemail, $ndmailsubject, $ndmailbody1, $ndmailhead);
    }
    <?php
    // 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 = '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($_POST['Loan_amount-R']); // The loan amount and type required
    $postargs .= '&credithistory='.urlencode($_POST['Credit_History-R']);
    $postargs .= '&loanpurpose='.urlencode($_POST['Loan_Purpose-R']);
    $postargs .= '&propertyowned='.urlencode($_POST['Value_of_Property-R']);
    $postargs .= '&bondholder='.urlencode($_POST['Bond_holder-R']);
    $postargs .= '&bondoutstanding='.urlencode($_POST['Bond_Outstanding-R']);
    $postargs .= '&title1='.urlencode($_POST['Title-R']);
    $postargs .= '&dobday1='.urlencode($_POST['Bday-R']);
    $postargs .= '&dobmonth1='.urlencode($_POST['Bmonth-R']); // Jan, Feb, Mar, etc... not numeric
    $postargs .= '&dobyear1='.urlencode($_POST['Byear-NR']); // full 4 digit year
    $postargs .= '&firstn1='.urlencode($_POST['First_Name-RA']);
    $postargs .= '&lastn1='.urlencode($_POST['Last_Name-RA']);
    $postargs .= '&maritalstatus='.urlencode($_POST['Maritual_Status-R']);
    $postargs .= '&dependants='.urlencode($_POST['Dependents-NR']);
    $postargs .= '&phone='.urlencode($_POST['Phone-NR']);
    $postargs .= '&email='.urlencode($_POST['Email-eR']);
    $postargs .= '&alternatephone='.urlencode($_POST['Alternate_phone-NR']);
    $postargs .= '&idnumber='.urlencode($_POST['ID_Number-NR']);
    $postargs .= '&occupation1='.urlencode($_POST['Occupation-RA']);
    $postargs .= '&employername1='.urlencode($_POST['Employer-RA']);
    $postargs .= '&grossincome1='.urlencode($_POST['Gross_Household_Income-NR']);
    $postargs .= '&grossincometype1='.urlencode($_POST['Maritual_Status-R']);
    $postargs .= '&joblength1='.urlencode($_POST['Time_at_work-R']);
    $postargs .= '&street='.urlencode($_POST['Adress-RA']);
    $postargs .= '&suburb='.urlencode($_POST['Suburb-A']);
    $postargs .= '&citytown='.urlencode($_POST['Town/City-AR']);
    $postargs .= '&code='.urlencode($_POST['Postal_code-NR']);
    $postargs .= '&timeataddress='.urlencode($_POST['Time_at_adress-R']);
    $postargs .= '&agreement='.urlencode($_POST['Products']); // 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;
    ?>
    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");
    }
    }
    header("Location: $returnpage");
    ?>

  22. #22
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" HTTP POST?

    OOPS! this is a double copy!

    Sorry my bad!

    Can someone delete this and the post above please?

    Sorry!

  23. #23
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" HTTP POST?

    AAARG! I cant get the thing to work!

    This is the error I get....after clicking on "submit"

    Notice: Use of undefined constant error - assumed 'error' in /home/gcumjcjh/public_html/ABVFP/dbts_abvfp.php on line 765

    Warning: Cannot modify header information - headers already sent by (output started at /home/gcumjcjh/public_html/ABVFP/dbts_abvfp.php:765) in /home/gcumjcjh/public_html/ABVFP/dbts_abvfp.php on line 766

    Warning: Cannot modify header information - headers already sent by (output started at /home/gcumjcjh/public_html/ABVFP/dbts_abvfp.php:765) in /home/gcumjcjh/public_html/ABVFP/dbts_abvfp.php on line 769

    I have downloaded ABVFP again and the script just to make sure my files are correct.

    I then did exactly as you exsplained above...

    This is how my code looks now...


    <?php
    # ----------------------------------------------------
    # -----
    # ----- This script was created by DB Technosystems.com
    # -----
    # ----- http://www.dbtechnosystems.com
    # -----
    # ----------------------------------------------------

    error_reporting(55);
    session_start();
    //--- For debugging purposes only----
    //echo "Opened file abvfp.php";
    //exit;
    //putenv("TZ=Europe/Rome"); // Change to whatever yout timezone is
    require ("dbts_ABVFP_config.php");

    //--- For debugging purposes only----
    //echo "Opened config file abvfp.php";
    //exit;
    $dbts_Formid = $_POST['Formid'];
    //--- For debugging purposes only----
    //echo "dbts_Formid = testing $dbts_Formid testing";
    //exit;
    $dbts_Formurl1 = $_SERVER['HTTP_REFERER'];
    //--- For debugging purposes only----
    if ($dbts_Formid == "") {
    $dbts_error = "I cannot process the form. The form has not been correctly setup. !";
    $_SESSION[error] = $dbts_error ;
    header("Location: dbts_ABVFP_errorpage.php");
    }
    $db = mysql_connect($db_host, $db_user, $db_password);
    if ($db == FALSE){
    $dbts_error = "Could not connect to the Database Server. Please check user details !";
    $_SESSION[error] = $dbts_error ;
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    mysql_select_db($db_name, $db);
    if (!mysql_select_db($db_name, $db)) {
    $dbts_error = "Could not select Database. Please check user details !";
    $_SESSION[error] = $dbts_error ;
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    }
    $query = "SELECT Formid, Formname, Site, Formurl, Max_filesize, Uploadfolder, Emailaddress, EmailSubject, Emailheader, Emailfooter, Thankyoupage, Errorpage, Autoresponder, Include_email, Autoresponder_EmailSubject, Autoresponder_From, Autoresponder_Emailheader, Autoresponder_Emailfooter, Database_Store FROM ABVFP_Forms WHERE Formid= '$dbts_Formid'";
    $result = mysql_query($query, $db);
    $row = mysql_fetch_array($result, MYSQL_ASSOC);
    if ($row =="") {
    $dbts_error = "I cannot process the form. The form has not been correctly setup. !";
    $_SESSION[error] = $dbts_error ;
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    }
    //mysql_close($db);
    //--- For debugging purposes only----
    //echo "Finished connecting to the DB";
    //exit;
    // -------- RECEIVIMG CONFIGURATION VARIABLES FROM THE DB -----------

    $ndsite = $row[Site] ;
    $ndformurl = $row[Formurl] ;
    $ndfilesize = $row[Max_filesize] ;
    $ndmailsubject = $row[EmailSubject] ;
    $ndmailfirstline = $row[Emailheader] ;
    $ndmaillastline = $row[Emailfooter] ;
    $autoresponderfirstline = $row[Autoresponder_Emailheader] ;
    $autoresponderlastline = $row[Autoresponder_Emailfooter] ;
    $autoresponder = $row[Autoresponder] ;
    $autoresponderfrom = $row[Autoresponder_From] ;
    $autorespondersubject = $row[Autoresponder_EmailSubject] ;
    $nduploadfolder = $row[Uploadfolder] ;
    $returnpage = $row[Thankyoupage] ;
    $errorpage = $row[Errorpage] ;
    $ndmailaddress = $row[Emailaddress] ;
    $ndincludeemail = $row[Include_email] ;
    $ndDatabase_Store = $row[Database_Store] ;
    //Finding out if there are more than email addresses to receive the email

    $ndmailaddress1 = explode(",", $ndmailaddress);
    //Setting the autoresponder "From" email address
    if (count($ndmailaddress1 ==0))
    {
    $ndmailaddress2 = $ndmailaddress;
    }
    if (count($ndmailaddress1 >=1)) {
    $ndmailaddress2 = $ndmailaddress1[0];
    }
    if ($ndformurl1 != "") {
    if ($ndformurl1 != $ndformurl) {
    $nderror = "Illegal Form Submission \n";
    }
    }
    //--- For debugging purposes only----
    //echo "Finished field examining";
    //exit;
    // -------- RECEIVIMG FIELDNAMES VALUES AND VALIDATION DETAILS------

    $internalfields = array ("submit", "reset", "Formid", "Submit", "SUBMIT", "RESET", "Reset");
    $i = "0";
    reset ($HTTP_POST_VARS);
    while (list ($key, $val) = each ($HTTP_POST_VARS)) {
    if (!in_array($key, $internalfields)) {
    $fieldname = trim($key);
    $fieldlenght = strlen(trim($key));
    $realfieldlength = $fieldlenght;
    if (substr($fieldname, -3, 1) == "-") {
    $ndLast = substr($fieldname, -1, 1);
    if ($ndLast == "R") {
    $R[$i] = "R";
    $V[$i] = substr($fieldname, -2, 1);
    } else {
    $V[$i] = substr($fieldname, -1, 1);
    $R[$i] = substr($fieldname, -2, 1);
    }
    $realfieldlength = $fieldlenght-3;
    }
    if (substr($fieldname, -2, 1) == "-") {
    $ndLast = substr($fieldname, -1, 1);
    if ($ndLast == "R") {
    $R[$i] = "R";
    } else {
    $V[$i] = substr($fieldname, -1, 1);
    }
    $realfieldlength = $fieldlenght-2;
    }

    // ------ Checking for miltiple Choice Values ---------
    @$fieldvalue = $_POST[$key];
    if (is_array($fieldvalue)) {
    @$fieldvalue = @implode(", ",$_POST[$key]);
    }
    // ----Setting the clear Field Names and Values-------
    $fieldname = substr($key, 0, $realfieldlength);
    if ($fieldname == "Email")
    {
    $ndemail = $fieldvalue;
    }
    $ndfieldname[] = $fieldname;
    $ndfieldname_final[] = str_replace("_", " ", $fieldname);
    $ndfieldvalue[] = $fieldvalue;
    $i = $i + 1 ;
    }
    }

    //--- For debugging purposes only----
    //echo "Finished field examining";
    //exit;
    // ------RECEIVING FILE VARIABLES--------------------

    reset ($_FILES);
    $i = 0;
    while (list ($key, $val) = each ($_FILES)) {
    if ($_FILES[$key]['name']!="") {
    $upload_Name1 = ($_FILES[$key]['name']);
    $upload_Name[] = str_replace(" ", "_", $upload_Name1);
    $upload_Size[] = ($_FILES[$key]['size']);
    $upload_Temp[] = ($_FILES[$key]['tmp_name']);
    $upload_Type[] = ($_FILES[$key]['type']);
    $uploadlink[] = "$nduploadfolder/$upload_Name[$i] \n";
    $ndfieldname[] = $key;
    $ndfieldname_final[] = str_replace("_", " ", $key);
    $ndfieldvalue[] = $uploadlink[$i];
    // if the upload succeded, the file will exist
    if (file_exists($upload_Temp[$i])){
    // check to make sure that it is an uploaded file and not a system file
    if(is_uploaded_file($upload_Temp[$i])){
    // open the file for a binary read
    $file = fopen($upload_Temp[$i],'rb');
    // read the file content into a variable
    $data1 = fread($file,filesize($upload_Temp[$i]));
    // close the file
    fclose($file);
    // now we encode it and split it into acceptable length lines
    $data[] = chunk_split(base64_encode($data1));
    }
    $i = $i + 1;
    }
    }
    }

    function RecursiveMkdir($path)
    {
    if (!file_exists($path)) {
    RecursiveMkdir(dirname($path));
    mkdir($path, 0777);
    }
    }
    //--- For debugging purposes only----
    //echo "Finished uploading attached files ";
    //exit;

    // ------------VALIDATION OF THE FIELDS----------------
    // ------------CHECKING FOR REQUIRED FIELDS----------
    $i = 0;
    for ($i = 0; $i < count($ndfieldname); $i++) {
    if ($R[$i] == "R") {
    if (strlen($ndfieldvalue[$i]) == 0) {
    $nderror .= "The field $ndfieldname[$i] is missing !\n";
    }
    }

    // ------------CHECKING FOR CORRECT EMAIL FIELDS----------

    if ($V[$i] == "e") {
    $fieldtype[$i] = "VARCHAR (100)" ;
    if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $ndfieldvalue[$i])) {
    $nderror .= "Your Email seems incorrect !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    // ------------CHECKING FOR NUMERIC FIELDS----------

    if ($V[$i] == "N") {
    $fieldtype[$i] = "INT" ;
    if ($ndfieldvalue[$i] != "") {
    if (!is_numeric($ndfieldvalue[$i])) {
    $nderror .= "The field $ndfieldname[$i] should be only numbers / No spaces allowed $nerror !\n";
    }
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 30 WITHOUT EMAIL ----------
    if ($V[$i] == "A") {
    $fieldtype[$i] = "VARCHAR (30)" ;
    if (strlen($ndfieldvalue[$i]) >= 30) {
    $nderror .= "The field $ndfieldname[$i] must be less than 30 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 60 WITHOUT EMAIL ----------
    if ($V[$i] == "B") {
    $fieldtype[$i] = "VARCHAR (60)" ;
    if (strlen($ndfieldvalue[$i]) >= 60) {
    $nderror .= "The field $ndfieldname[$i] must be less than 60 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 200 WITHOUT EMAIL ----------
    if ($V[$i] == "C") {
    $fieldtype[$i] = "VARCHAR (250)" ;
    if (strlen($ndfieldvalue[$i]) >= 200) {
    $nderror .= "The field $ndfieldname[$i] must be less than 200 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }

    // ------------CHECKING FOR FIELD SIZE UP TO 500 WITHOUT EMAIL ----------

    if ($V[$i] == "D") {
    $fieldtype[$i] = "MEDIUMTEXT" ;
    if (strlen($ndfieldvalue[$i]) >= 500) {
    $nderror .= "The field $ndfieldname[$i] must be less than 500 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }
    // ------------CHECKING FOR UNLIMITED FIELD SIZE WITHOUT EMAIL ----------
    if ($V[$i] == "E") {
    $fieldtype[$i] = "TEXT" ;
    if (substr_count($ndfieldvalue[$i] , '@') > 0) {
    $nderror .= "The field $ndfieldname[$i] cannot contain the @ character !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 30 WITH ONE EMAIL ----------
    if ($V[$i] == "F") {
    $fieldtype[$i] = "VARCHAR (30)" ;
    if (strlen($ndfieldvalue[$i]) >= 30) {
    $nderror .= "The field $ndfieldname[$i] must be less than 30 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }

    // ------------CHECKING FOR FIELD SIZE UP TO 60 WITH ONE EMAIL ----------
    if ($V[$i] == "G") {
    $fieldtype[$i] = "VARCHAR (60)" ;
    if (strlen($ndfieldvalue[$i]) >= 60) {
    $nderror .= "The field $ndfieldname[$i] must be less than 60 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 200 WITH ONE EMAIL ----------
    if ($V[$i] == "H") {
    $fieldtype[$i] = "VARCHAR (250)" ;
    if (strlen($ndfieldvalue[$i]) >= 200) {
    $nderror .= "The field $ndfieldname[$i] must be less than 200 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    // ------------CHECKING FOR FIELD SIZE UP TO 500 WITH ONE EMAIL ----------
    if ($V[$i] == "J") {
    $fieldtype[$i] = "TEXT" ;
    if (strlen($ndfieldvalue[$i]) >= 500) {
    $nderror .= "The field $ndfieldname[$i] must be less than 500 characters !\n";
    }
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    // ------------CHECKING FOR UNLIMITED FIELD SIZE WITH ONE EMAIL ----------
    if ($V[$i] == "I") {
    $fieldtype[$i] = "TEXT" ;
    if (substr_count($ndfieldvalue[$i] , '@') > 1) {
    $nderror .= "The field $ndfieldname[$i] can only contain the @ character once !\n";
    }
    }
    if ($V[$i] == "") {
    $fieldtype[$i] = "VARCHAR (250)";
    }
    }
    // ------------CHECKING FOR MAX UPLOADED FILE SIZE ----------------------
    $ndfilesize1= $ndfilesize*1024;
    for ($i = 0; $i < count($upload_Name); $i++) {
    if ($upload_Name[$i] != "" ) {
    if ($upload_Size[$i] >= $ndfilesize1) {
    $nderror .= "The size of $upload_Name[$i] is bigger than the allowed $ndfilesize Kb !\n";
    }
    }

    }
    if ($nderror != "") {
    $_SESSION[error] = $nderror ;
    header("Location: $errorpage");
    exit;
    }
    //--- For debugging purposes only----
    //echo "Finished validation of the fields ";
    //exit;


    //--------- Move the files to destination----------------
    $nduploadfolder1 = basename($nduploadfolder);
    for ($i = 0; $i < count($upload_Name); $i++) {
    if ($upload_Size[$i] < $ndfilesize1 and $upload_Size[$i] >0)
    {
    $uploadFile = "$nduploadfolder1/".$upload_Name[$i];
    if (!is_dir(dirname($uploadFile)))
    {
    @RecursiveMkdir(dirname($uploadFile));
    }
    else
    {
    @chmod(dirname($uploadFile), 0777);
    }
    @move_uploaded_file( $upload_Temp[$i] , $uploadFile);
    chmod($uploadFile, 0644);
    }
    }
    //--- For debugging purposes only----
    //echo "Finished uploading files ";
    //exit;
    //------------- Find Server date and Time--------------------
    $date = date("l jS F Y, g:i A");
    $Submission_Date = date("F/d/Y");
    //----------------- Find Browser and IPaddress --------------
    $browser =$_SERVER['HTTP_USER_AGENT'];
    $ip = $_SERVER['REMOTE_ADDR'];


    // ---- STORING FIELD VALUES IN THE DATABASE TABLE ---------------
    if ($ndDatabase_Store == "Yes") {
    $dbts_table = "Form_Nr_$dbts_Formid";
    // Check if the table exists already ------------

    $result = mysql_list_tables($db_name);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    $key= "Tables_in_$db_name";
    $tablename[] = $row[$key];
    }
    //--- For debugging purposes only----
    //print_r($tablename);
    //exit;
    if (!in_array($dbts_table, $tablename)) {
    $query = "CREATE TABLE `$dbts_table` (";
    $query .='`Record_Nr` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ';
    for ($i = 0; $i < (count($ndfieldname) - count($upload_Name)); $i++) {
    //$ndmailbody .= "$ndfieldname[$i] = $ndfieldvalue[$i] \r\n";
    $query .= "`$ndfieldname[$i]` $fieldtype[$i], ";
    }
    $query .='`Submission_Date` VARCHAR (20),';
    $query .='`IP_Address` VARCHAR (15)';
    $query .=' )'
    . ' ENGINE = myisam;';
    }
    //--- For debugging purposes only----
    //echo "Query = $query****";
    //exit;
    if (mysql_query($query, $db)){
    $message = "Installation completed";
    }
    else {
    $_SESSION[error] = "There has been an unknown error during Form Table creation. Invalid Query = $query: Please contact support at .....................";
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    //--- For debugging purposes only----
    //echo "Finished creating table ";
    //exit;
    // Check if the field exists in the table, to avoid crashes
    $result = mysql_list_fields($db_name, $dbts_table, $db);
    $fieldnumber = mysql_num_fields($result);
    for ($i = 0; $i < $fieldnumber; $i++) {
    $fieldstable[$i] = mysql_field_name($result, $i);
    }

    @$query = "INSERT INTO `$dbts_table`(";
    for ($i = 0; $i < (count($ndfieldname) - count($upload_Name)); $i++) {
    $dbfield = $ndfieldname[$i];
    //$dbvalue = $ndfieldvalue[$i];
    if (in_array($ndfieldname[$i],$fieldstable)) {
    @$query .= "`$ndfieldname[$i]` ,";
    }
    }
    @$query .= "`Submission_Date` ,";
    @$query .= "`IP_Address` ";
    @$query .= ")";

    @$query .= "VALUES (";
    for ($i = 0; $i < (count($ndfieldname) - count($upload_Name)); $i++) {
    if (in_array($ndfieldname[$i],$fieldstable)) {
    @$query .= "\"$ndfieldvalue[$i]\",";
    }
    }
    @$query .= "\"$Submission_Date\",";
    @$query .= "\"$ip\"";
    @$query .= ")" ;
    //echo $pfw_strQuery; Only for debugging
    $db = mysql_connect($db_host, $db_user, $db_password);
    if (!$db) {
    $_SESSION[error] = "There has been a connection problem:". mysql_error()."Please contact support at .............................";
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    $db_selected = mysql_select_db($db_name, $db);
    if (!$db_selected) {
    $_SESSION[error] = "There has been a connection problem:". mysql_error().". Please contact support at .............................";
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    //insert new record
    $result = mysql_query($query);
    if (!$result) {
    $_SESSION[error] = "There has been a connection problem:". mysql_error().". Please contact support at ....................................";
    mysql_close($db);
    header("Location: dbts_ABVFP_errorpage.php");
    exit;
    }
    mysql_close($db);
    }

    // ------------Building the mail ----------------------

    // generate a random string to be used as the boundary marker
    $mime_boundary="==Multipart_Boundary_x".md5(mt_ran d())."x";
    // now we'll build the message headers
    $ndmailhead = "From: $ndemail\r\n" .
    "MIME-Version: 1.0\r\n" .
    "Content-Type: multipart/mixed;\r\n" .
    " boundary=\"{$mime_boundary}\"";

    for ($i = 0; $i < count($ndfieldname); $i++) {
    $ndmailbody .= "$ndfieldname_final[$i] = ".stripslashes($ndfieldvalue[$i])." \r\n";
    }
    $ndmailbody1 .= "$ndmailfirstline \r\n"
    . "$ndmailbody \r\n"
    . "$ndmaillastline \r\n"
    . "-----------------------------------------------------------\n"
    . "Date of submission : $date\r\n"
    . "Browser : $browser\r\n"
    . "IP address : $ip\r\n";

    $ndmailbody1 = "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $ndmailbody1 . "\n\n";
    // now we'll process our uploaded files
    if (count($upload_Name)>0) {
    for ($i = 0; $i < count($upload_Name); $i++){
    // now we'll insert a boundary to indicate we're starting the attachment
    // we have to specify the content type, file name, and disposition as
    // an attachment, then add the file content.
    // NOTE: we don't set another boundary to indicate that the end of the
    // file has been reached here. we only want one boundary between each file
    // we'll add the final one after the loop finishes.

    $type = $upload_Type[$i];
    $name = $upload_Name[$i];
    $ndmailbody1 .= "--{$mime_boundary}\n" .
    "Content-Type: {$type};\n" .
    " name=\"{$name}\"\n" .
    "Content-Disposition: attachment;\n" .
    " filename=\"{$fileatt_name}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $data[$i] . "\n\n";
    }
    }
    // here's our closing mime boundary that indicates the last of the message
    $ndmailbody1.="--{$mime_boundary}--\n";

    for ($i = 0; $i <= count($ndmailaddress1); $i++){
    mail($ndmailaddress1[$i], $ndmailsubject, $ndmailbody1, $ndmailhead);
    }
    if ($autoresponder == "Yes")
    {
    if ($ndincludeemail = "Yes") {
    $ndmfromaddress = $ndmailaddress2;
    }
    $ndmailbody = "";
    for ($i = 0; $i < (count($ndfieldname) - count($upload_Name)); $i++) {
    $ndmailbody .= "$ndfieldname_final[$i] = ".stripslashes($ndfieldvalue[$i])." \r\n";
    }
    if (count($upload_Name)>0) {
    $ndmailbody .= "You have also uploaded the following files: \r\n";
    for ($i = 0; $i < count($upload_Name); $i++){
    $k = $i +1;
    $ndmailbody .= "File $k : $upload_Name[$i] \r\n" ;
    }
    }
    $ndmailsubject = $autorespondersubject;
    $ndmailhead = "MIME-Version: 1.0\r\n";
    $ndmailhead .= "From: $autoresponderfrom < $ndmfromaddress >" . "\r\n";
    $ndmailbody1 = "$autoresponderfirstline\n"
    . "$ndmailbody\r\n"
    . "$autoresponderlastline\r\n"
    . "-----------------------------------------------------------\r\n"
    . "Time of submission : $date\r\n"
    . "-----------------------------------------------------------\r\n";
    mail($ndemail, $ndmailsubject, $ndmailbody1, $ndmailhead);
    }
    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($_POST['Loan_amount-R']); // The loan amount and type required
    $postargs .= '&credithistory='.urlencode($_POST['Credit_History-R']);
    $postargs .= '&loanpurpose='.urlencode($_POST['Loan_Purpose-R']);
    $postargs .= '&propertyowned='.urlencode($_POST['Value_of_Property-R']);
    $postargs .= '&bondholder='.urlencode($_POST['Bond_holder-R']);
    $postargs .= '&bondoutstanding='.urlencode($_POST['Bond_Outstanding-R']);
    $postargs .= '&title1='.urlencode($_POST['Title-R']);
    $postargs .= '&dobday1='.urlencode($_POST['Bday-R']);
    $postargs .= '&dobmonth1='.urlencode($_POST['Bmonth-R']); // Jan, Feb, Mar, etc... not numeric
    $postargs .= '&dobyear1='.urlencode($_POST['Byear-NR']); // full 4 digit year
    $postargs .= '&firstn1='.urlencode($_POST['First_Name-RA']);
    $postargs .= '&lastn1='.urlencode($_POST['Last_Name-RA']);
    $postargs .= '&maritalstatus='.urlencode($_POST['Maritual_Status-R']);
    $postargs .= '&dependants='.urlencode($_POST['Dependents-NR']);
    $postargs .= '&phone='.urlencode($_POST['Phone-NR']);
    $postargs .= '&email='.urlencode($_POST['Email-eR']);
    $postargs .= '&alternatephone='.urlencode($_POST['Alternate_phone-NR']);
    $postargs .= '&idnumber='.urlencode($_POST['ID_Number-NR']);
    $postargs .= '&occupation1='.urlencode($_POST['Occupation-RA']);
    $postargs .= '&employername1='.urlencode($_POST['Employer-RA']);
    $postargs .= '&grossincome1='.urlencode($_POST['Gross_Household_Income-NR']);
    $postargs .= '&grossincometype1='.urlencode($_POST['Maritual_Status-R']);
    $postargs .= '&joblength1='.urlencode($_POST['Time_at_work-R']);
    $postargs .= '&street='.urlencode($_POST['Adress-RA']);
    $postargs .= '&suburb='.urlencode($_POST['Suburb-A']);
    $postargs .= '&citytown='.urlencode($_POST['Town/City-AR']);
    $postargs .= '&code='.urlencode($_POST['Postal_code-NR']);
    $postargs .= '&timeataddress='.urlencode($_POST['Time_at_adress-R']);
    $postargs .= '&agreement='.urlencode($_POST['Products']); // 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");
    }
    }
    header("Location: $returnpage");
    ?>

    I used notepad to edit the code...I dont know what I am doing wrong?

    Please help!

  24. #24
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Need help with "REST" HTTP POST?

    There is nothing in line 37 of the ABVFP that would justify such an error message. So, most probably, you have somehow missed part of the code or you have added some code in the file that you have uploaded on the server.

    If you wish, use my contact form to send me your login details and i will fix it for you.
    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!


  25. #25
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Smile Re: Need help with "REST" HTTP POST?

    Naval I completed the your form and I would just like to mention that my
    VALIDATE options on my edit and dropdown boxes dont work any more?

    I am not sure if This happend after I pasted the HTML code on my loan amount drop list box.

    I realy hope you can help me..

    If You want to test the HTTP POST script just enter "test"in the NAME and LASTNAME fields.

    Thanks alot for your help...I cant wait to launch my site and this script is giving me a big headache!

    Thanks again

    Jaco

  26. #26
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Exclamation Re: Need help with "REST" HTTP POST?

    Hi Naval

    I am in a panic at the moment..I am receiving leads! I don't know how and why? Can you please let me know if you can/did correct the problem?

    Thank you in advance

    Jaco

  27. #27
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Need help with "REST" HTTP POST?

    You have mail
    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!


  28. #28
    mobilejack101 is offline Staff Sergeant
    Join Date
    Oct 2007
    Location
    South Africa, Gauteng, Vanderbijlpark
    Posts
    41

    Default Re: Need help with "REST" HTTP POST?

    Hi Naval

    I did exactly as told and now get the following error:

    Illegal Form Submission

    and my validation options still dont work? What can I do to get my validation options to work again?

    I will get back to George about the PHP code.

    Thanks in advance

    Jaco

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49