【问题标题】:WFFM form POST and redirectWFFM 表单 POST 和重定向
【发布时间】:2012-04-04 04:41:14
【问题描述】:

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

我已使用第 3 方 POST 测试工具确认我的表单 POST 可以正常工作。我遇到的问题是,在 Sitecore 中,他们使用 successMode 来确定如果提交成功,用户想要做什么。如果用户选择了successmode/message,表单会重定向回感谢信息。如果用户选择成功模式/重定向,成功方法管道会在表单中查找成功页面值,然后重定向到该 URL。重定向的问题是它丢失了我的 POST 数据。

谁能提供一个 Sitecore 示例,说明他们如何执行表单 POST,然后在不丢失 POST 值的情况下重定向到目标外部 URL?

您是否使用了表单中的成功模式设置?

我正在讨论是否覆盖成功模式重定向管道、添加条件和测试,但我愿意接受可能包含 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; }

        }


    }

【问题讨论】:

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


    【解决方案1】:

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

    如果您真的需要任何 WFFM 终端功能,您可以轻松调用它们...这仍然比尝试覆盖 WFFM 基本功能以注入您自己的功能要容易得多。

    【讨论】:

    • 命令模板已创建并部署以复制我的基本表单。因此,当用户单击付款表单时,他们会在其网站表单站点根目录中创建一个带有新 ID 的基本付款表单。问题是专门关于发布到外部 URL 的。顺便说一句,当开发人员必须为营销人员提供解决方案时,覆盖是一种常见的做法,在我们的例子中,它需要这样的解决方案。请告诉我如何在不使用 WFFM 的情况下在表单标签中创建输入类型字段。
    • 如果我觉得我很粗鲁,我很抱歉。我不是故意的。根据您的要求,在我看来,您基本上是在编写所有自己的代码来处理表单提交,而不是使用任何 WFFM 功能。
    • 要回答您的问题,简单地说,使用 WFFM 很容易,但它相当有限,因为定制迫使您在模块的范围内工作。如果您不喜欢使用 WFFM 模块,我建议您在这里做的是创建自己的自定义保存操作,然后将其分配给表单。如果您查看 WFFM 文档的参考资料,其中有一节是关于创建保存操作的。您可以编写所有自己的代码来处理提交到外部站点的操作,它使您可以访问作为对象的字段。
    • 这是从自定义成功模式命令和表单中的保存操作执行的,因此是“ISaveAction”界面。 Sitecore 包含无法更改的内置 js 回发方法。因此,一旦回发发生,POST 数据就会被擦除。问题不在于提交到另一个站点(曾经在那里),而是通过回发保持值。
    • 哇。祝你好运。我认为,在你对一个只是想帮助的人的居高临下的态度和你固执地坚持你的方钉确实适合一个圆孔之间,我要鞠躬,让你去解决这个问题。祝你好运。
    猜你喜欢
    • 2015-11-04
    • 1970-01-01
    • 2013-08-17
    • 2020-02-17
    • 2015-12-02
    • 2013-12-31
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多