tags:

views:

806

answers:

2

I'm trying to allow a web form to use a PayPal buy it now. The relevant page is: http://tinyurl.com/ykz44ay

Based on which radio button a user selects, depends on which paypal button they are "redirected" to. The subscriptions are easy - they are just a simple redirect.

The last option, requires a user select a venue. For this, i require to use the form below:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="10956105">
<table>
<tr><td><input type="hidden" name="on0" value="Venue">Venue</td></tr><tr><td>
<input type="text" name="os0" maxlength="60"></td></tr>
</table>
<input type="image" src="https://www.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

But of course, I want to do it without using that form.

What I have so far is:

 if (singleOneOff.Checked)
            {
                paypalForm.Text = getPaypalForm(venueSelect.SelectedItem.Text);
                var strJS = getPayPalPostJS("_xclick");
                paypalJs.Text = strJS;
                var xxx = "dd";
            }

This determines if that particular radio button was ticked.

getPaypalForm

private String getPaypalForm(string venue)
{
    StringBuilder strForm = new StringBuilder();
    strForm.Append(@"<form action=""https://www.paypal.com/cgi-bin/webscr"" name=""_xclick"" method=""post"">");
    strForm.Append(@"<input type=""hidden"" name=""cmd"" value=""_s-xclick"">");
    strForm.Append(@"<input type=""hidden"" name=""hosted_button_id"" value=""10956105"">");
    strForm.Append(@"<input type=""hidden"" name=""on0"" value=""Venue"">");
    strForm.Append(@"<input type=""text"" name=""os0"" value=""{0}"" maxlength=""60"">");
    strForm.Append("</form>");

    return String.Format(strForm.ToString(), venue);
}

getPayPalPostJS

private String getPayPalPostJS(string strFormId)
{
    StringBuilder strScript = new StringBuilder();
    strScript.Append("<script language='javascript'>");
    strScript.Append("var paypalForm = document.forms.namedItem('{0}');");
    strScript.Append("paypalForm.submit();");
    strScript.Append("</script>");
    return String.Format(strScript.ToString(), strFormId);
}

However, if i select the radio button, and a venue, and press the button, nothing happens....

Any ideas where i've gone wrong?

I followed this guide: http://www.netomatix.com/development/postrequestform.aspx

+2  A: 

Here's a much cleaner, server-side solution to the ASP.NET/PayPal single form problem:

http://codersbarn.com/post/2008/03/08/Solution-to-ASPNET-Form-PayPal-Problem.aspx

IrishChieftain
+1  A: 

The root of the problem is that ASP.Net web forms wrap everything on the page inside of one large <form> tag. Your paypal code is rendering a nested form and that doesn't work.

Read this question for more information.

Lance McNearney