|
List Info
Thread: Pass HTML Form to PHP, Validate Input, then Send to GC
|
|
| Pass HTML Form to PHP, Validate Input,
then Send to GC |
  United States |
2007-03-20 18:33:24 |
I've been going back and forth on this and might be making
the PHP API
more Complex than it needs to be. I am comfortable with html
forms,
post, php and xml (somewhat) Here goes:
My HTML page has a seven item HTML Form with several hidden
inputs and
one text field with a quantity value for each item that the
user fills
in. GC will not accept any item values with 0 or blank, so
I am
submitting the form to a PHP parser which strips out all the
hidden
items with no quantity and then submits that to GC...to
summarize:
HTML Form -> PHP strips out no-quantity items -> PHP
submits to GC.
Here is my simple PHP code (my merchant # has been changed
for
protection:
[code]
<?php
$items = array("item_quantity_1=0&",
"item_quantity_2=0&");
$body = file_get_contents('php://input');
$cart = str_replace($items,"",$body);
$form = "<form method="post"
name="orders" action="https://
checkout.google.com/cws/v2/Merchant/xxx/checkoutForm"&
gt;".
$cart."<form>";?>
<html>
<head>
<script language="JavaScript"
type="text/JavaScript"> function
submitcheckout(){ var form = document.orders; form.submit();
} </
script>
</head>
<body> <?php echo $form ?>
<input type="image"
onload="submitcheckout()" name="Google
Checkout"
alt="Fast checkout through Google" src="https://checkout.google.
com/
buttons/checkout.gif?
merchant_id=xxx&w=168&h=44&style=trans&varia
nt=text&loc=en_US"
height="46" width="180"/>
</body>< </html>
[/code]
I am well aware that this is covered in detail in the XML
and/or PHP
API, but again I've been going around in circles and am
becoming more
confused. I'm sure that I'm not the only one. Any help
appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "API Integration Basics" group.
To post to this group, send email to
google-checkout-api-integration googlegroups.com
To unsubscribe from this group, send email to
google-checkout-api-integration-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/google-checko
ut-api-integration?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Pass HTML Form to PHP, Validate
Input, then Send to GC |

|
2007-03-21 08:37:57 |
|
Jonathan hi
i think that ur issue is that u are not respecting the items numeration
if you post 4 items, and the remove #1 and #2, the post hidden will be item_quantity_3
and item_quantity_4
and as u can see in this specs, Google Checkout expects item_quantity_1 and item_quantity_2
before 3 and 4 http://code.google.com/apis/checkout/developer/google_checkout_html_api.html#checkout_api
double check that please
hope this helps
btw, also double check the output form that ur script is producing, because i dont think is correct.
i would use some thing like this
<?php
$cart = ""; foreach($_POST as $key => $value) { if(!($value <= 0)) { $cart .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
} }
$form = "<form method="post" name="orders" action="https://checkout.google.com/cws/v2/Merchant/xxx/checkoutForm
">" . $cart . "<form>"; ?> <html> <head> <script language="JavaScript" type="text/JavaScript"> function submitcheckout(){ var form =
document.orders; form.submit(); } </script> </head> <body> <?php echo $form; ?> <input type="image" onload="submitcheckout()" name="Google Checkout" alt="Fast checkout through Google" src="
https://checkout.google.com/buttons/checkout.gif?merchant_id=xxx&w=168&h=44&style=trans&variant=text&loc=en_US
" height="46" width="180"/> </body> </html>
Note: review this code, i coded in the mail :P, didnt test it
ropu
On 3/20/07,
Jonathan4Gs < jonathan7 gmail.com">jonathan7 gmail.com> wrote:
I've been going back and forth on this and might be making the PHP API more Complex than it needs to be. I am comfortable with html forms, post, php and xml (somewhat) Here goes:
My HTML page has a seven item HTML Form with several hidden inputs and
one text field with a quantity value for each item that the user fills in. GC will not accept any item values with 0 or blank, so I am submitting the form to a PHP parser which strips out all the hidden items with no quantity and then submits that to GC...to summarize:
HTML Form -> PHP strips out no-quantity items -> PHP submits to GC.
Here is my simple PHP code (my merchant # has been changed for protection:
[code]
<?php
$items = array("item_quantity_1=0&", "item_quantity_2=0&");
$body = file_get_contents(9;php://input'); $cart = str_replace($items,"",$body);
$form = "<form method="post" name="orders" action="https://
checkout.google.com/cws/v2/Merchant/xxx/checkoutForm">". $cart."<form>";?> <html> <head> <script language="JavaScript" type="text/JavaScript"> function
submitcheckout(){ var form = document.orders; form.submit(); } </ script> </head> <body> <?php echo $form ?> <input type="image" onload="submitcheckout()" name="Google Checkout"
alt="Fast checkout through Google" src="https://checkout.google.com/ buttons/checkout.gif? merchant_id=xxx&w=168&h=44&style=trans&variant=text&loc=en_US"
height="46" width="180"/> </body>< </html>
[/code]
I am well aware that this is covered in detail in the XML and/or PHP API, but again I've been going around in circles and am becoming more
confused. I9;m sure that I'm not the only one. Any help appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "API Integration Basics" group. To post to this group, send email to google-checkout-api-integration googlegroups.com To unsubscribe from this group, send email to google-checkout-api-integration-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/google-checkout-api-integration?hl=en -~----------~----~----~----~------~----~------~--~---
|
[1-2]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|