Allowing HTML Form Submissions From DNN 

At one point or another everyone has a need to include an HTML form within a DNN website. This might be to link to a PayPal Buy it now button or one of many other options. Well as most of us know it is not possible to simply put a HTML form into a Text/HTML module and have the form submit. This is due to the ASP.NET form that is existing in the website that is used to handle all server side controls. However, there is a fairly simple method to allow the form to post using some simple javascript. A special thanks goes to John Mitchell who covered this specifically relating to the PayPal Buy it now buttons in this blog post.

To include an HTML form within DNN you will first need to note the "Action" property that is set in the <form> tag. Once you know this action you will want to remove the opening and closing form tags. Now, in the HTML source location the submit button (<Input type="submit"> or similar) . Then add the following inside the tag declaration.

onClick="this.form.action='YourUrlHere';this.form.submit();"

Be sure to put your Action URL inplace of the "YourUrlHere" text. This tells the HTML form that if the submit button is clicked that it should change the form action, which will prevent ASP.NET postback and then it actually submits the form to the new URL.

This provides you a quick and reliable method to submit HTML forms to external sites. This isn't the best solution as other input items on the current page will be submitted to the action page, however, typically that is not too large of an issue.

NOTE: this also works in any other ASP.NET application.

Posted by Mitchel on Tuesday, April 03, 2007
 

Comments

Thanks for sharing. I've got a few comments on DNN forms <href="http://seablick.com/blog/tabid/53/articletype/articleview/articleid/21/formidable-dnn-forms.aspx">here</p>.

By Tom Kraak on Thursday, April 05, 2007 at 7:46 AM

Call me stupid, but what/where is the "tag declaration?

By Joe on Friday, December 14, 2007 at 6:27 PM

Joe,

I apologize I should have been a bit more specific.

You would simply put the code in question inside the input tag something like.

<input type="submit" onClick="..." />

By mitchel.sellers@gmail.com on Saturday, December 15, 2007 at 4:28 PM

Thanks for your "how to". I tried it and it almost works. It does redirect me to the submit page, but no values get carried over. With my form the goal is to submit the form and then it should populate another asp form on another webserver. Is there an issue with going across servers? -- Thanks.

By oconshaw on Monday, January 07, 2008 at 3:24 PM

I tried again -- I placed the asp form in a test html page with the javascript code on the same site and posted to the form in question. Works great.

Then I moved the html file with the javascript code to another site and posted to that same site. Again it worked. So there isn't an issue with posting across servers.

The issues seems to be with DNN. Any ideas? Here is my code -- pretty simple.

<input type="hidden" value="1" name="posted" /> <input type="hidden" value="" name="sprice" /> <input type="text" size="20" name="stext" class="search" value="test"/> <input type="image" src="http://testsite123.com/images/go.gif" onClick="this.form.action='http://testsite123.com/search.asp';this.form.submit();" name="Submit" />

Thanks in advance.

By oconshaw on Monday, January 07, 2008 at 4:17 PM

Do any of the form values get posted to the site?

By mitchel.sellers@gmail.com on Monday, January 07, 2008 at 7:06 PM

Going from DNN to the other site -- no values get transferred. Going from a traditional static html site (on the same server or remote) the values do get posted. I tested out the post from DNN to see if anything was going across by posting to another form page (on another site) that just does a response.write for posted values -- nothing comes across. In all cases the code for doing the form posting is the same. It seems like there is something with DNN that is breaking the post. -- Thanks again.

By oconshaw on Tuesday, January 08, 2008 at 8:43 AM

Funny how topical this is as I am also trying to post (unsuccessfully) to an external site as of yesterday, and found this thread. Same deal as the previous poster - simply can't pass some values when trying to come out of DNN. Separate html/asp does fine, which does me no good.

By Eric on Thursday, January 10, 2008 at 4:44 PM

One thing that might be causing problems is if your submission page validates on specific form input names. The reason this can be an issue is changing the post location of a .NET form does ALSO post any other form properties that are used elsewhere in the page, and at times that causes issues.

By mitchel.sellers@gmail.com on Friday, January 11, 2008 at 4:52 AM

I want to add "Form Action" tag and "Get Method" in DNN. how to do!

How to send request and retrieve results using Form Action in DNN.

I need explanation in my email.

Email address: joegomes_86@hotmail.com

By Joe G on Friday, February 22, 2008 at 12:56 AM

Hello,
I have followed your instructions to "fix" the form you can see here: http://www.financialconsultantsguide.com/Resources/tabid/59/Default.aspx

However, it does nto work: the onclik actio is started but immediately overwritten by something else that returns back to the site. i changed the original code from:
<TABLE border=0 cellPadding=0 cellSpacing=0 width=510 bgcolor=#003366>

</TABLE>

to

<table cellSpacing=0 cellPadding=0 width=510 bgColor=#003366 border=0>
<tbody>
<tr>
<td align=right width=98>
<img height=26 hspace=5 src="http://www.investorwords.com/iwheader2.gif" width=98></td>
<td align=right width=128>
<img height=32 hspace=5 src="http://www.investorwords.com/searchforaterm.gif" width=114></td>
<td width=175><input size=25 name=term> </td>
<td vAlign=bottom width=100 vspace="2">
<input onclick="this.form.action='http://www.investorwords.com/cgi-bin/searchTerms.cgi';this.form.submit();" type=image height=22 cache width=84 src="http://www.investorwords.com/searchpic.gif" border=0 name=searchImage target="InvestorWords" method="get"> </td></tr></tbody></table>

An example where it works fine (not a dnn site) is: http://www.inter-lawyer.com/group/tools/finance-glossary.htm

What am I doing wrong?
Thank you in advance.

Franco

By Franco on Thursday, May 15, 2008 at 12:17 PM

Hi, it is me again. I think I managed to make it run by avoiding to use the rich-text editor when editing the html module.
However, I have two major issues still:

1. I am not capable of opening a new window as aresult of the "onclick" action.
2. The input text is not passed on to the site.

Thank you again for your help.
Best,
Franco

By Franco on Thursday, May 15, 2008 at 12:45 PM

Franco,

Can you please move this discussion to the forum, I try to keep all technical assistance to that area of the site.

Thank you!!

By mitchel.sellers@gmail.com on Thursday, May 15, 2008 at 6:14 PM

how i include forms in dnn site.
can u explain for me.

By velu on Friday, July 25, 2008 at 1:10 AM

Thanks!! You saved my life! Works fantastic with the Paypal Website Payments Standard.

By Ben on Monday, August 25, 2008 at 8:27 PM

Thanks so much for your help today, Mitchel! This solution worked like a charm.

By Tim Gossett on Saturday, November 08, 2008 at 5:28 PM

No problem Tim! I'm glad it worked, and thanks for coming to IowaCodeCamp, and my presentation

By mitchel.sellers@gmail.com on Saturday, November 08, 2008 at 8:31 PM

Thanks a lot . It works !!!

By Htoo Myat on Monday, December 15, 2008 at 9:57 PM
Click here to post a comment

Donate

Show your appreciation for the content/modules made available by MitchelSellers.com by making a donation. Donations are used to assist with dedicating time to creating free content.