如何订阅点击HTML表单的事件? [英] How to subscribe to click event of html form?

查看:173
本文介绍了如何订阅点击HTML表单的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个谷歌结帐立即购买按钮,我想添加动态创建的信息,单击时发送。我该怎么做呢?

I have a google checkout "buy now" button and I want to add dynamically created information to send when it's clicked. How do I do that?

按钮的HTML是:

<form action="https://sandbox.google.com/checkout/..." id="Form1" method="post" name="..." target="_top">
<input name="item_name_1" type="hidden" value="..." />
...
<input alt="" src="https://sandbox.google.com/checkout/buttons/buy.gif?merchant_id=..." type="image" />
</form>

所以,我该怎么加? (如果可能的话,我想做到这一点通过ASP.Net code)

So what do I add? (And if possible, I'd like to do that through ASP.Net code.)

我尝试添加的onclick =的button1_Click,但没有奏效。

I tried adding onclick="Button1_Click" but it didn't work.

推荐答案

如果这是对谷歌Checkout的,你应该考虑使用现有的谷歌为结帐网库。

If this is for Google Checkout, you should consider using the existing .Net library for Google Checkout.

虽然上述建议将工作,做正确的(安全)方式,以便为<一个href=\"https://developers.google.com/checkout/developer/Google_Checkout_HTML_API#create_checkout_cart\"相对=nofollow>此处记录。该XML替代(签约)是这里,其中一个让你做一个直接表单POST到谷歌在一个安全的方式。

While the above suggestion will work, the correct (secure) way of doing so is documented here. The XML alternative (signing) is here, one of which allows you to do a direct FORM POST to Google in a secure manner.

通过客户端方式提交总会让你容易被篡改 - 这将使相差不大(安全明智)不只是做一个基本的HTML表单提交给谷歌

Submission via client methods will always make you susceptible to tampering - it would make little difference (security-wise) than just doing a basic HTML form post to Google.

更新

... 不支持现在购买 ...

在这一天结束时,有两件事情,使任何其他购物车提交现在购买的不同:

At the end of the day, there are 2 things that make "BUY NOW" different from any other "cart" submission:


  1. 图像

  2. 单项采购的立即购买(与一个或多个其他实现)。

请参阅此<一个href=\"http://$c$c.google.com/p/google-checkout-dotnet-sample-$c$c/source/browse/examples/post_cart/simple.aspx\"相对=nofollow>样本code从.NET库。它应该给你所有你需要....

See this sample code from the .Net Library. It should give you all you need....

更新2

有没有什么刚性关于库。你不必在其使用的一切 - 你甚至可以只取已经为您创建的所有管道的优势

There isn't anything "rigid" about the library. You don't have to use everything in it - you can even just take advantage of all the plumbing already created for you.

Web窗体code(CSS):

Web Forms Code (aspx):

<p>Some ASP.net button:<br />
<asp:Button ID="Button1" runat="server" Text="BUY ME NOW" onclick="Button1_Click" /><br />

An ASP.NET Image Button using BUY NOW Image:<br />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="https://checkout.google.com/buttons/buy.gif?merchant_id=[USE YOUR OWN MERCHANT ID]&amp;w=117&amp;h=48&amp;style=white&amp;variant=text&amp;loc=en_US" onclick="ImageButton1_Click" />

在这一点上,这是你在你的浏览器中看到:

At this point this is what you see in your browser:

code(inline或code-后面):

Code (inline or code-behind):

using GCheckout.Checkout;
using GCheckout.Util;

....

protected void Button1_Click(object sender, EventArgs e)
{
    doSomething();
}

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    doSomething();
}

private void doSomething()
{
    /**
     * Use the correct Merchant ID and Key based on GCheckout.EnvironmentType
     * You cannot mix/match sandbox and production id or key
     */
    CheckoutShoppingCartRequest Req = new CheckoutShoppingCartRequest("your_production_MID", "your_production_KEY", GCheckout.EnvironmentType.Production, "USD", 20);

    /**
     * Everything from this point is a copy and paste
     * from .net libary sample code
     * http://code.google.com/p/google-checkout-dotnet-sample-code/source/browse/examples/post_cart/simple.aspx
     */
    Req.AddItem("Mars bar", "Packed with peanuts", 0.75m, 2);

    //lets make sure we can add 2 different flat rate shipping amounts
    Req.AddFlatRateShippingMethod("UPS Ground", 5);

    //Add a rule to tax all items at 7.5% for Ohio
    Req.AddStateTaxRule("OH", 7.5, true);

    GCheckoutResponse Resp = Req.Send();
    if (Resp.IsGood)
    {
        Response.Redirect(Resp.RedirectUrl, true);
    }
    else
    {
        Response.Write("Resp.ResponseXml = " + Resp.ResponseXml + "<br>");
        Response.Write("Resp.RedirectUrl = " + Resp.RedirectUrl + "<br>");
        Response.Write("Resp.IsGood = " + Resp.IsGood + "<br>");
        Response.Write("Resp.ErrorMessage = " + Resp.ErrorMessage + "<br>");
    }
}

重要

以上就是样品code 来说明你可以用NET库做什么。 要遵守谷歌Checkout的实施政策,使用的ImageButton实施 - (未改变等)。它确保您使用的是谷歌的立即购买按钮

Important

The above is just sample code to illustrate what you can do with the .Net Library. To comply with Google Checkout implementation policy, use the ImageButton implementation - it ensures that you are using Google's BUY NOW button (unaltered, etc.).

这篇关于如何订阅点击HTML表单的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆