Back to all posts

Allowing HTML Form Submissions From DNN

Posted on Apr 03, 2007

Posted in category:
Development
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 an 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.

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.

Sample Addition to Submit Button

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

Be sure to put your Action URL in place 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.