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
country flaguser name
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-integrationgooglegroups.com
To unsubscribe from this group, send email to
google-checkout-api-integration-unsubscribegooglegroups.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
user name
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 = "&quot;;
foreach($_POST as $key => $value) {
 &nbsp;  if(!($value <= 0)) { 
 &nbsp;   &nbsp;  $cart .= '<input type=";hidden&quot; name=";' . $key . '"; value=&quot;' . $value . '"; />';
 &nbsp;  }
}

$form = "<form method=&quot;post&quot; name=";orders&quot; action=&quot;https://checkout.google.com/cws/v2/Merchant/xxx/checkoutForm &quot;>&quot; . $cart . "<form>&quot;;
?>
<html>;
<head&gt;
<script language=&quot;JavaScript" type=";text/JavaScript">
   ; function submitcheckout(){
&nbsp; &nbsp;  &nbsp;  var form = document.orders;
&nbsp; &nbsp;  &nbsp;  form.submit();
 &nbsp;  }
</script>
</head>
&lt;body>
<?php echo $form; ?>
<input type=";image";  onload=&quot;submitcheckout()&quot; name=";Google Checkout&quot; alt="Fast checkout through Google&quot; src=" https://checkout.google.com/buttons/checkout.gif?merchant_id=xxx&amp;w=168&amp;h=44&;style=trans&variant=text&;loc=en_US " height=&quot;46" width=&quot;180"/>
</body>
&lt;/html>

Note: review this code, i coded in the mail :P, didnt test it

ropu


On 3/20/07, Jonathan4Gs < jonathan7gmail.com">jonathan7gmail.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.&nbsp; 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 ; ->; &nbsp;PHP submits to GC.

Here is my simple PHP code (my merchant # has been changed for
protection:

[code]

<?php

$items = array(&quot;item_quantity_1=0&amp;", "item_quantity_2=0&&quot;);

$body = file_get_contents(9;php://input');
$cart = str_replace($items,&quot;",$body);

$form = "<form method=&quot;post&quot; name=";orders&quot; action=&quot;https://
checkout.google.com/cws/v2/Merchant/xxx/checkoutForm">".
$cart."&lt;form>&quot;;?>
<html&gt;
<head>
<script language=&quot;JavaScript" type=";text/JavaScript"> function
submitcheckout(){ var form = document.orders; form.submit(); } </
script>
</head>
&lt;body> <?php echo $form ?>
<input type=";image"; &nbsp;onload=&quot;submitcheckout()&quot; name=";Google Checkout&quot;
alt="Fast checkout through Google&quot; src="https://checkout.google.com/
buttons/checkout.gif?
merchant_id=xxx&w=168&h=44&amp;style=trans&variant=text&amp;loc=en_US"
height=&quot;46" width=&quot;180"/>
</body><; </html&gt;

[/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&quot; group.
To post to this group, send email to google-checkout-api-integrationgooglegroups.com
To unsubscribe from this group, send email to google-checkout-api-integration-unsubscribegooglegroups.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 )