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 here

.

By Tom Kraak on Thursday, April 05, 2007 at 12:46 PM

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

By Joe on Friday, December 14, 2007 at 11: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.

By mitchel.sellers@gmail.com on Saturday, December 15, 2007 at 9: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 8: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.



Thanks in advance.

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

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

By mitchel.sellers@gmail.com on Tuesday, January 08, 2008 at 12:06 AM

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 1:43 PM

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 9: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 9: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 5: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:





to












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 5: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 5: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 11:14 PM

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

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

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

By Ben on Tuesday, August 26, 2008 at 1:27 AM

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

By Tim Gossett on Saturday, November 08, 2008 at 10: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 Sunday, November 09, 2008 at 1:31 AM

Thanks a lot . It works !!!

By Htoo Myat on Tuesday, December 16, 2008 at 2:57 AM

Got a problem now. I did what was suggested here. It works, but it causes the Login or the EDIT TEXT button to also submit the request.

Is there a way to avoid this.

By DnnUser on Tuesday, January 20, 2009 at 10:19 PM

DnnUser,

Please post to the forums for specific assistance.

By mitchel.sellers@gmail.com on Tuesday, January 20, 2009 at 11:29 PM

I am trying to submit a form that is passing form data from an HTML module and have tried everything on this posting including other approaches discussed on ASP.NET Forums and still having no success. I also searched in your Forums and found nothing discussing the details of how to make this work.

By Ty on Saturday, May 02, 2009 at 2:06 PM

Wouldn't it be GREAT if the HTML module had an option to automatically correct HTML Forms, so they worked without any tweaking?

By Lucas Jans on Friday, July 10, 2009 at 9:39 AM

Hello,
All I need to do is have the form emailed to a specific address...not sent to another url. What would my action script look like then?

Thank you tons!!

By Emily on Tuesday, July 14, 2009 at 3:28 PM

Hey Mitch, thanks again for more rock solid assistance on a DNN challange. Got my MailChimp sign up working like a charm on our DNN site.

By Michael Mock on Thursday, March 11, 2010 at 6:33 PM

This works well, so long as there is only one form. For multiple forms, an IFrame approach works, except that if the Submit takes you to another site, it will come up within the IFrame.

By Tim Thornton on Wednesday, May 04, 2011 at 4:30 AM

Hi, I have the same problem on this page here: http://www.friendsofrefugees.com/Donate/tabid/612/Default.aspx

Sounds like everyone found the solution... I couldn't seem to see it in the comments here.

By Bruce on Thursday, July 07, 2011 at 1:31 PM

This works great - but I have struggled with calling a JavaScript function to validate a drop list (embedded with the PayPal button) in the onclick event. I am moving working code from HTML pages to DNN, so no problem with the JavaScript. Problem is that when I add function call to onclick, either only the function is called with no post, or nothing happens (depending on the permutation). I have also tried moving the code you provide above to the JavaScript function, to post if valid but no joy (could be me). Any chance of an updated example that includes a call to validate_form()?

By Scott Buchanan on Tuesday, October 25, 2011 at 10:56 AM

Scott,

I'd have to see exactly what you are trying to do.

By mitchel.sellers@gmail.com on Tuesday, October 25, 2011 at 1:08 PM

FYI to all who find this thread (which has been quite useful). This is broken in DNN 6.1.0 - the HTML module strips out all input tags - see http://www.dotnetnuke.com/Resources/Forums/forumid/200/threadid/436905/scope/posts.aspx for DNN response and workaround.

By Scott Buchanan on Friday, November 04, 2011 at 7:58 AM

Scott,

Thanks for the post!

By mitchel.sellers@gmail.com on Friday, November 04, 2011 at 9:22 AM

Thanks. New to DNN. Just the hint i needed. Thought I was going crazy when the form tag just disappeared.

Since it basically seemed to strip the form tag away,
here's the hack I ended up using (assuming jQuery is there):

Assume your original form is in a div.



I added this script behind the closing div:



The form handling is nice and clean, sending only what it needs to.

By Eric on Monday, January 30, 2012 at 6:36 PM

Name (required)

Email (required)

Website

CAPTCHA image
Enter the code shown above:

Content provided in this blog is provided "AS-IS" and the information should be used at your own discretion.  The thoughts and opinions expressed are the personal thoughts of Mitchel Sellers and do not reflect the opinions of his employer.

Friend of RedGate

www.datasprings.com - DotNetNuke ModulesICG

Click here for advertising information.

Content in this blog is copyright protected.  Re-publishing on other websites is allowed as long as proper credit and backlink to the article is provided.  Any other re-publishing or distribution of this content is prohibited without written permission from Mitchel Sellers.