Page view counter

Submitting a form to an external site using DNN

Rate It (2)

Last post 09-27-2005 6:06 PM by DevDave. 77 replies.

Sort Posts:

  • Submitting a form to an external site using DNN

    04-07-2005, 11:11 AM
    • Loading...
    • DevDave
    • Joined on 10-31-2003, 7:18 AM
    • Southwest Florida
    • Posts 288
    • Points 1,407

    I have a customer who uses a CRM and a Merchant account, both of which require you to use an HTML form to submit information to their site. 

    Since, in ASP.NET (and DNN) all pages are already inside of a form, is there a way to incorporate/send forms to these sites from within DNN?

    Currently, I'm using two techniques, but neither is ideal.  On one site, I'm using the <iframe> tag to show a form created on a separate html page.  The problem with this is that when redirected to the next page after submitting the form, it too shows inside of the <iframe>.

    On the other site, I've made the entire form on an html page, the look of which mimics the DNN skin being used on the rest of the site.  The drawbacks are obvious... I'm not using DNN for that page and updates to the skin must be manually carried over to the form.

    Any suggestions?

    Thanks,
    David

  • Re: Submitting a form to an external site using DNN

    04-08-2005, 7:22 PM
    • Loading...
    • DevDave
    • Joined on 10-31-2003, 7:18 AM
    • Southwest Florida
    • Posts 288
    • Points 1,407

    Has anyone else needed to send a form to an external site from DNN?

    David

  • Re: Submitting a form to an external site using DNN

    04-08-2005, 11:34 PM
    • Loading...
    • ndr
    • Joined on 04-22-2004, 12:00 PM
    • Dallas, Texas
    • Posts 118
    • Points 590
    I have  similiar requirement and would be interested in the answer as well.
    Thanks, Chad
  • Re: Submitting a form to an external site using DNN

    04-09-2005, 3:10 AM
    • Loading...
    • nbc
    • Joined on 06-29-2002, 12:06 AM
    • Perth, Western Australia
    • Posts 1,469
    • Points 7,345

    You do have a number of options;

    - the iframe you mentioned. In the html form set the post/get action to open the form results in a new window and you have a quick and dirty way to get the job done.
    - buy one of the form modules that let you do this, I think (but not 100% sure) Xmod and the like let you build a form that can be submitted to an external url
    - build a simple dnn module to do the same thing

    EDIT - do a search on these forums, I remember someone posting code that used javascript to post a form so you didn't need form tags in the html.

  • Re: Submitting a form to an external site using DNN

    04-09-2005, 9:10 AM
    • Loading...
    • J7Mitch
    • Joined on 10-19-2002, 1:23 PM
    • Posts 2,632
    • Points 13,145
    • TrustedFriends-MVPs

    Check out my post to this thread: http://forums.asp.net/857770/ShowPost.aspx

    John M.

    DotNetNuke Module for Performance
  • Re: Submitting a form to an external site using DNN

    04-09-2005, 6:21 PM
    • Loading...
    • mbblum
    • Joined on 03-08-2004, 4:47 PM
    • Posts 64
    • Points 314
    You can also use dotNet's System.Net.WebRequest object to post data in code behind.

    I have a function written in C# that uses WebRequest. It accepts two strings, a URI and PostData, and returns as string the response from the page. If it will help, I can post the code segment. I may have a VB translation, though will have to search for that.

    mbb


  • Re: Submitting a form to an external site using DNN

    04-10-2005, 3:31 PM
    • Loading...
    • DevDave
    • Joined on 10-31-2003, 7:18 AM
    • Southwest Florida
    • Posts 288
    • Points 1,407
    Thanks so much for the feedback.

    mbb,  I'd love to see the code segment if you have the time.

    Thanks,
    David

  • Re: Submitting a form to an external site using DNN

    04-10-2005, 5:39 PM
    • Loading...
    • jonmoore
    • Joined on 03-28-2004, 5:18 PM
    • London/Herts, UK
    • Posts 34
    • Points 170
    javascript may be overkill:  paypal links don't have to be submitted as a form, they work just as well using a get rather than post, ie you can construct as a simple hyperlink, just add all the form fields to the url...
  • Re: Submitting a form to an external site using DNN

    04-10-2005, 10:41 PM
    • Loading...
    • mbblum
    • Joined on 03-08-2004, 4:47 PM
    • Posts 64
    • Points 314
    David, I've seen your request, but will be tomorrow before code is posted. A snowstorm here in Colorado is resultng in some other priorities.

    mbb
  • Re: Submitting a form to an external site using DNN

    04-11-2005, 10:18 AM
    • Loading...
    • DevDave
    • Joined on 10-31-2003, 7:18 AM
    • Southwest Florida
    • Posts 288
    • Points 1,407

    Please, no rush.  I've implemented the work-arounds already, but will be doing this again in the near future.

    Thanks again,
    David

  • Re: Submitting a form to an external site using DNN

    04-11-2005, 10:48 AM
    • Loading...
    • cniknet
    • Joined on 07-23-2002, 7:19 PM
    • Washington, DC
    • Posts 1,915
    • Points 9,585

    This gives me an interesting idea for a DotNetNuke component -- one that can be used in any module to retrieve data from a remote form post using XMLHttp. This could be done completely client-side and allow for the U.I. to be updated without postbacks.

     if (window.XMLHttpRequest)
    {
          req = new XMLHttpRequest(); 
          req.open("POST", url , false); 
          req.send(null);
    }
    else if (window.ActiveXObject)

          req = new ActiveXObject("Microsoft.XMLHTTP"); 
          if (req) 
             { 
                req.open("POST", url, false); 
                req.send(); 
             }
    }

    Nik

     

    Nik Kalyani
    Speerio, Inc.

    [DotNetNuke and ASP.Net solutions here]
  • Re: Submitting a form to an external site using DNN

    04-11-2005, 11:50 AM
    • Loading...
    • AllegrettoA
    • Joined on 03-01-2005, 11:10 PM
    • Posts 45
    • Points 225

    Another idea is a module that enables authoring of stand-alone html content.  This would be similar to the Text/HTML module except that content would be rendered to a asp/aspx file and viewed through an IFRAME.  This would enable active server page processing, forms, and scripting which would not interfere with the DNN page.  The module could even pass in UserID, ModuleID, and other querystring parameters.

    This could provide another degree of freedom that is sometimes needed by web developers.  Although files are created, they would be managed with DNN.

  • Re: Submitting a form to an external site using DNN

    04-11-2005, 11:56 AM
    • Loading...
    • mbblum
    • Joined on 03-08-2004, 4:47 PM
    • Posts 64
    • Points 314
    The MSDN Library has some good information on using WebRequest. Here is a starting link:
    "Deriving from WebRequest" from .NET Framework Developer's Guide

    Below is ithe C# function using WebRequest.
    Some notes:
    - The Method property is set to "POST" in code. A more generic version would allow setting the Method verb to go with the protocol specified in the URI by passing the verb to use.
    - This function was created expecting http:// protocol, though WebRequest can handle others.
    - The "using" objects is for the entire class, and has more entries than are needed for this function. I did not check which are the extras. WebRequest is in System.Net.

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web;
    using System.Web.Services;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Net;
    using System.IO;


          /// <summary>
          /// Method opens the specified URL, 'POST' the data string,
          /// and returns the returned response from the url address.
          /// </summary>
          /// <param name="URL">URL to server application with http protocol</param>
          /// <param name="POSTdata">data string properly formated to POST to the specified URL.</param>
          /// <returns>The response returned by the application at the URL location.</returns>
          /// <history>
          ///      [mbb] 7/15/2004 Created
          /// </history>
          public string UrlPOST(string URL, string POSTdata)
          {
             StringBuilder rtnValue = new StringBuilder();
             bool isValidParams = true;

             // check for url
             if (URL.Length < 10)
             {
                isValidParams = false;
                throw new Exception("URL = '" + URL + "' is not a valid URL.");
             }
             else if (URL.IndexOf("://") <= 0)
             {
                isValidParams = false;
                throw new Exception("URL = '" + URL + "' is not a valid URL. URL must include protocol, e.g. 'http://'");
             }

             if (isValidParams)
             {
                WebResponse result = null;
                try
                {
                   // setup WebRequest object
                   WebRequest request = WebRequest.Create(URL);
                   request.Method = "POST";
                   request.Timeout = 3000;
                   request.ContentType = "application/x-www-form-urlencoded";

                   // add payload for POST to request stream
                   byte[] SomeBytes = null;
                   SomeBytes = Encoding.UTF8.GetBytes(POSTdata);
                   request.ContentLength = SomeBytes.Length;
                   Stream newStream = request.GetRequestStream();
                   newStream.Write(SomeBytes, 0, SomeBytes.Length);
                   newStream.Close();

                   // POST data and get response
                   result = request.GetResponse();
                   Stream receive = result.GetResponseStream();
                   Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                   StreamReader stream = new StreamReader(receive, encode);
                   char[] read = new char[256];
                   int count = stream.Read(read, 0, 256);
                   // read through response to clear buffers, etc.
                   while (count > 0)
                   {
                      string str = new string(read, 0, count);
                      rtnValue.Append(str);
                      count = stream.Read(read, 0, 256);
                   }
                }
                catch (Exception ex)
                {
                   throw ex;
                }
                finally
                {
                   if (!(result == null))
                   {
                      result.Close();
                      result = null;
                   }
                }
             }
             return rtnValue.ToString();
          }
       }

    Hope this is helpful.
    mbb
  • Re: Submitting a form to an external site using DNN

    04-11-2005, 12:07 PM
    • Loading...
    • codegalaxy
    • Joined on 06-29-2004, 5:00 PM
    • Topeka (Alma), Kansas
    • Posts 1,475
    • Points 6,910
    I would also be interested in your code because I have to get something like this done this week if possible.
    Dylan Barber
    read my stupid blog http://codemypantsoff.com
    Pants Optional!
  • Re: Submitting a form to an external site using DNN

    04-11-2005, 12:27 PM
    • Loading...
    • J7Mitch
    • Joined on 10-19-2002, 1:23 PM
    • Posts 2,632
    • Points 13,145
    • TrustedFriends-MVPs

    Here's a way to do it in code-behind:

    Imports System

    Imports System.IO

    Imports System.Net

    Imports System.Xml

    Imports System.Text

    Imports System.Text.RegularExpressions

    Imports System.Web.Security

    Public Sub PostHTTP(ByVal Url As String)

        Dim HTMLResponse As New StringBuilder

        Dim form_data As String = Request.Form.ToString

        'remove the viewstate & other Event items that start with two underscores

        form_data = Regex.Replace(form_data, "__.*?=.*?Dog [&]?", "")

        Dim byte_data As Byte() = Encoding.UTF8.GetBytes(form_data.ToString)

        Dim NewRequest As HttpWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)

        NewRequest.Method = "POST"

        NewRequest.ContentType = "application/x-www-form-urlencoded"

        NewRequest.ContentLength = byte_data.Length

        NewRequest.AllowAutoRedirect = True

        'add the Cookies of the current Request to the New Request

        Dim HeaderCookieValues As String() = Request.Headers.GetValues("Cookie")

        For Each HeaderCookieValue As String In HeaderCookieValues
            HeaderCookieValue = HeaderCookieValue & NewRequestCookies.ToString
            NewRequest.Headers.Add("Cookie", HeaderCookieValue)
        Next

        Dim oNewRequestStream As Stream = NewRequest.GetRequestStream()

        oNewRequestStream.Write(byte_data, 0, byte_data.Length)

        oNewRequestStream.Close()

        Dim oHttpWebResponse As HttpWebResponse = CType(NewRequest.GetResponse(), HttpWebResponse)

        Dim oNewResponseStream As Stream = oHttpWebResponse.GetResponseStream()

        HTMLResponse.Append(New StreamReader(oNewResponseStream).ReadToEnd())

        oNewResponseStream.Close()

        Response.Clear()

        Response.Write(HTMLResponse.ToString)

        Response.Flush()

        Response.End()

    End Sub

    John M.

    DotNetNuke Module for Performance
Page 1 of 6 (78 items) 1 2 3 4 5 Next > ... Last ยป