WFFM表单POST和重定向

时间:2012-03-27 15:28:45

标签: sitecore sitecore6 web-forms-for-marketers

我粗略地遵循了这个例子,但它没有解决我与Sitecore相关的重定向问题。 sitecore web form for marketers form post to external url

我已经通过使用第三方POST测试工具确认我的表单POST正常工作。我遇到的问题是,在Sitecore中,如果提交成功,他们会使用successMode来确定用户想要的内容。如果用户选择successmode / message,表单将重定向回感谢消息。如果用户选择successmode / redirect,则成功方法管道在表单中查找成功页面值,然后重定向到该URL。重定向的问题是它丢失了我的POST数据。

任何人都可以提供Sitecore示例,了解他们如何执行表单POST,然后重定向到目标外部URL而不会丢失POST值吗?

您是否在表单中使用了successmode设置?

我正在讨论是否要覆盖成功模式重定向管道,添加条件和测试,但我愿意接受可能包含jquery的解决方案。

这是我的代码:

        using Sitecore.Data;
    using Sitecore.Form.Core.Client.Data.Submit;
    using Sitecore.Form.Core.Controls.Data;
    using Sitecore.Form.Submit;
    using System.Web;
    using Sitecore.Web.UI.HtmlControls;
    using Sitecore.Text;
    using Sitecore.Forms.Core.Data;
    using Sitecore.Form.Core.Configuration;
    using Sitecore.Forms.Core.Crm;
    using System;
    using System.IO;
    using System.Net;
    using Sitecore.Diagnostics;
    using System.Text;

    namespace XXXWffmExternals
    {
        public class Redirect : ISaveAction      
        {                
            UrlString url = new UrlString("https://XXX.XXX/default.asp");

            public virtual void Execute(ID formid, AdaptedResultList fields, params object[] data)
            {
                String strResult = "";            
                strResult = setPost(url.ToString(), fields); 

            }

            public String setPost(string url, AdaptedResultList fieldListForPOST)
            {
                String resultReturn = "";

                AdaptedControlResult firstname = fieldListForPOST.GetEntry(this.First_Name, "First_Name");
                AdaptedControlResult lastname = fieldListForPOST.GetEntry(this.Last_Name, "Last_Name");
                AdaptedControlResult billingaddress = fieldListForPOST.GetEntry(this.Billing_Address, "Billing_Address");
                AdaptedControlResult billingcity = fieldListForPOST.GetEntry(this.Billing_City, "Billing_City");
                AdaptedControlResult billingstate = fieldListForPOST.GetEntry(this.Billing_State, "Billing_State");
                AdaptedControlResult billingzip = fieldListForPOST.GetEntry(this.Billing_Zip, "Billing_Zip");
                AdaptedControlResult billingphone = fieldListForPOST.GetEntry(this.Billing_Phone, "Billing_Phone");
                AdaptedControlResult email = fieldListForPOST.GetEntry(this.Email, "Email");
                AdaptedControlResult amount = fieldListForPOST.GetEntry(this.Amount, "Amount");
                AdaptedControlResult desc = fieldListForPOST.GetEntry(this.Description, "Description");
                AdaptedControlResult login = fieldListForPOST.GetEntry(this.Login, "Login");
                AdaptedControlResult acct = fieldListForPOST.GetEntry(this.Account, "Account");
                AdaptedControlResult fund = fieldListForPOST.GetEntry(this.Fund, "Fund");
                AdaptedControlResult org = fieldListForPOST.GetEntry(this.Org, "Org");

                AdaptedControlResult source_code = fieldListForPOST.GetEntry(this.Source_Code, "Source_Code");

                String post =
                    "First_Name=" + firstname.Value +
                    "&Last_Name=" + lastname.Value +
                    "&Billing_Address=" + billingaddress.Value +
                    "&Billing_City=" + billingcity.Value +
                    "&Billing_State=" + billingstate.Value +
                    "&Billing_Zip=" + billingzip.Value +
                    "&Billing_Phone=" + billingphone.Value +
                    "&Email=" + email.Value +
                    "&Amount=" + amount.Value +
                    "&Description=" + desc.Value +
                    "&Login=" + login.Value +
                    "&Account=" + acct.Value +
                    "&Fund=" + fund.Value +
                    "&Org=" + org.Value +
                    "&Invoice_Num=" + "DVXXXX";

                resultReturn = sendPost(url.ToString(), post); 

                return resultReturn;

            }

            public String sendPost(string url, string post)
            {

                String result = "";

                HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
                objRequest.Method = "POST";
                // Set credentials to use for this request.
                objRequest.Credentials = CredentialCache.DefaultCredentials;

                // Convert POST data to a byte array.           
                byte[] byteArray = Encoding.UTF8.GetBytes(post);

                // Set the ContentLength property of the WebRequest.
                objRequest.ContentLength = byteArray.Length;
                // Set the ContentType property of the WebRequest.
                objRequest.ContentType = "application/x-www-form-urlencoded";
                // Get the request stream.
                Stream dataStream = objRequest.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
                // Get the response.
                WebResponse response = objRequest.GetResponse();                      
                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream ();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader (dataStream);
                // Read the content.
                result = reader.ReadToEnd ();

                // Clean up the streams.
                reader.Close ();
                dataStream.Close ();
                response.Close ();
                return result;      


            }



            public string First_Name { get; set; }       
            public string Last_Name { get; set; }       
            public string Billing_Address { get; set; }
            public string Billing_City { get; set; }
            public string Billing_State { get; set; }
            public string Billing_Zip { get; set; }
            public string Billing_Phone { get; set; }
            public string Email { get; set; }
            public string Amount { get; set; }
            public string Description { get; set; }
            public string Login { get; set; }
            public string Account { get; set; }
            public string Fund { get; set; }
            public string Org { get; set; }
            public string Invoice_Num { get; set; }
            public string Source_Code { get; set; }

        }


    }

1 个答案:

答案 0 :(得分:0)

如果您不想调用任何WFFM功能,为什么要将WFFM用于表单? WFFM的目的是允许标记人员在没有任何开发人员输入的情况下创建自己的表单。您必须编辑代码中的所有发布数据,这几乎消除了任何人在没有开发人员输入的情况下编辑表单的能力。我会说,如果您要完成编写所有代码以手动提交代码的过程,您可以使用Sitecore项创建表单,然后使用您自己的代码进行处理。跳过WFFM。按照你的建议做事情比做手工创建表单要多得多。

如果你真的需要任何WFFM结束功能,你可以轻松地调用它们......它仍然比尝试覆盖WFFM基本功能以注入你自己的功能更容易。