Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Asif Malik 203 posts 339 karma points
    Jan 10, 2012 @ 14:13
    Asif Malik
    0

    Send form data to 3rd party

    Hi we have a client who would like us to use Umbraco Contour to create a form. This by default meets their first requirement of being able to create a form and the data from it can be exportable. The second step is that they would like to redirect the user to a third party site and also send the from data (as post) to the thrid party (in this case a payment providers payemnt page). The only way i can think of is by setting up a thank you page for the form with a hidden form which auto submits to the 3rd parties site.

    Is there a better way of doing this? You help and guidance is much appreciated

  • elspiko 133 posts 302 karma points
    Jan 10, 2012 @ 14:16
    elspiko
    0

    You could setup a workflow task that runs after a contour record has been approved and then sends the form data to the third party

  • Asif Malik 203 posts 339 karma points
    Jan 10, 2012 @ 14:36
    Asif Malik
    0

    Thanks for your quick reply. It is not just the form data that needs to be sent to the 3rd party webiste, the actual user needs to be redireted to their site. On their site they have a form which gets prefilled based on the form data that is sent to it.

  • Comment author was deleted

    Jan 11, 2012 @ 12:47

    Hi Asif,

    Well the workflows will happen in the background, if you want to send the user to another site you'll have to customize the workflow so that is does the redirect. You can download all the default providers on the contour project page

  • Asif Malik 203 posts 339 karma points
    Jan 11, 2012 @ 13:43
    Asif Malik
    0

    Hi Tim, thanks for your post. My understanding was that the workflows only did background tasks, thatnks for clearing this up, it should be relativly straight forward from here.

    Thanks

  • Asif Malik 203 posts 339 karma points
    Jan 11, 2012 @ 16:54
    Asif Malik
    0

    Hi Tim, thanks for your help so far, I have managed to get the redirection working. The next step is for me to map the contour form fields to the 3rd parties fields.

    Ideally i would like to create a custom FieldSetting that lists all of the forms fields with text boxes next to each of them where i could enter the 3rd parties field names, this will give me a mapping between the contour form fields and the 3rd parties fields.

    How would i go about creating this custom FieldSetting?

    Thanks

  • Asif Malik 203 posts 339 karma points
    Jan 12, 2012 @ 11:40
    Asif Malik
    0

    Hi Tim thanks for your help earlier, wanted to quickly update this post to indicate i have managed to get the custom workflow working with the help of a custom FieldSetting and a custom Control

    however i wanted to know if there are any side effects of not returning

    WorkflowExecutionStatus.Completed
    

    I assume that if there are any workflows after my one then they wont run, but aprat from that are there any other potential issues?

  • Martin Lingstuyl 202 posts 379 karma points
    Apr 04, 2012 @ 17:44
    Martin Lingstuyl
    0

    Hi Asif,

     

    Could you elaborate on how you got this done?! I'm wrestling with it too.

     

    Martin

  • Asif Malik 203 posts 339 karma points
    Apr 04, 2012 @ 18:53
    Asif Malik
    1

    This is my code, hope it helps you out. I have used a custom field setting, but later i found out i could have used

    [Attributes.Setting("Fields", description = "Map the needed fields", control = "Umbraco.Forms.Core.FieldSetting.FieldMapper")]
    

    to replace my FieldMappings

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using System.Xml;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Attributes;
    using Umbraco.Forms.Core.Enums;
    using Umbraco.Forms.Data;
    using Umbraco.Forms.Data.Storage;
    
    namespace PublicZone.Umb.Contour.Workflows
    {
        public class PostToNetBanx : WorkflowType
        {
            public PostToNetBanx ( )
            {
                this.Id = new Guid ( "ENTER-YOUR-OWN-GUID-HERE" );
                this.Name = "Send to external system";
                this.Description = "This workflow will post the user form data to an external system";
            }
    
            [Setting ( "Post Url", description = "Enter the URL of the external system", control = "Umbraco.Forms.Core.FieldSetting.TextField" )]
            public string PostUrl { getset; }
    
            [Setting ( "Merchant Reference", description = "Enter the NetBanx merchant reference", control = "Umbraco.Forms.Core.FieldSetting.TextField" )]
            public string nbxMerchantReference { getset; }
    
            [Setting ( "Success Url", description = "Enter the URL of the ", control = "Umbraco.Forms.Core.FieldSetting.TextField" )]
            public string nbxSuccessUrl { getset; }
    
            [Setting ( "Success Redirect Url", description = "Enter the URL of the ", control = "Umbraco.Forms.Core.FieldSetting.TextField" )]
            public string nbxSuccessRedirectUrl { getset; }
    
            [Setting ( "Currencey Code", description = "Enter the currency code to be used", control = "Umbraco.Forms.Core.FieldSetting.TextField" )]
            public string nbxCurrenceyCode { getset; }
    
            [Setting ( "Field Mappings", description = "Enter the currency code to be used", control = "PublicZone.Umb.Contour.FieldSetting.NetBanxMapper", assembly = "PublicZone.Umb.Contour" )]
            public string FieldMappings { getset; }
    
    
            public override WorkflowExecutionStatus Execute ( Record record, RecordEventArgs e )
            {
                RecordsViewer viewer = new RecordsViewer ( );
                XmlNode xml = viewer.GetSingleXmlRecord ( record, new XmlDocument ( ) );
                Dictionary<stringstring> netBanxFields = new Dictionary<stringstring> ( );
    
                string [ ] array = FieldMappings.Trim ( ).Split ( '|' );
    
                foreach ( string s in array )
                {
                    string [ ] a = s.Trim ( ).Split ( ',' );
    
                    if ( a.Length == 2 )
                    {
    
                        string formValue = "";
                        string netBanxField = "";
    
                        netBanxField = StringHelper.ParsePlaceHolders ( e.Context, record, a [ 1 ] );
    
                        if ( !string.IsNullOrEmpty ( a [ 0 ] ) )
                        {
                            formValue = record.RecordFields [ new Guid ( a [ 0 ] ) ].ValuesAsString ( );
                        }
    
                        if ( netBanxFields.ContainsKey ( netBanxField ) )
                        {
                            string newNetBanxField = netBanxFields [ netBanxField ] + " " + formValue;
                            netBanxFields [ netBanxField ] = newNetBanxField;
                        }
                        else
                        {
                            netBanxFields.Add ( netBanxField, formValue );
                        }
                    }
                }
    
    
    
                //HttpContext.Current.Response.Redirect ( PostUrl );
                StringBuilder rsmAuthForm = new StringBuilder ( );
                rsmAuthForm.Append ( "<html>" );
                rsmAuthForm.Append ( "<head>" );
                rsmAuthForm.Append ( "</head>" );
                //rsmAuthForm.Append ( "<body onload=\"document.auth.submit();\">" );
                rsmAuthForm.Append ( "<body>" );
                rsmAuthForm.Append ( "<form name=\"auth\" action=\"" + PostUrl + "\" method=\"post\">" );
    
                foreach ( KeyValuePair<stringstring> _field in netBanxFields )
                {
    
                    rsmAuthForm.Append ( "<input type=\"hidden\" name=\"" + _field.Key + "\" value=\"" + _field.Value + "\">" );
                }
    
                rsmAuthForm.Append ( "<input type=\"hidden\" name=\"nbx_merchant_reference\" value=\"" + nbxMerchantReference + "\">" );
                rsmAuthForm.Append ( "<input type=\"hidden\" name=\"nbx_success_url\" value=\"" + nbxSuccessUrl + "\">" );
                rsmAuthForm.Append ( "<input type=\"hidden\" name=\"nbx_success_redirect_url\" value=\"" + nbxSuccessRedirectUrl + "\">" );
                rsmAuthForm.Append ( "<input type=\"hidden\" name=\"nbx_currency_code\" value=\"" + nbxCurrenceyCode + "\">" );
                rsmAuthForm.Append ( "<p>If you are not automatically redirected, please click to proceed.</p>" );
                rsmAuthForm.Append ( "<p><input type=\"submit\" value=\"SUBMIT\"></p>" );
                rsmAuthForm.Append ( "</form>" );
                rsmAuthForm.Append ( "</body>" );
                rsmAuthForm.Append ( "</html>" );
    
                HttpContext.Current.Response.Clear ( );
                HttpContext.Current.Response.Write ( rsmAuthForm.ToString ( ) );
                HttpContext.Current.Response.End ( );
    
    
                return WorkflowExecutionStatus.Completed;
            }
    
            public override List<Exception> ValidateSettings ( )
            {
                List<Exception> l = new List<Exception> ( );
    
                if ( string.IsNullOrEmpty ( PostUrl ) )
                    l.Add ( new Exception ( "'PostUrl' setting not filled out'" ) );
    
                if ( string.IsNullOrEmpty ( nbxMerchantReference ) )
                    l.Add ( new Exception ( "'Merchant Reference' setting not filled out'" ) );
    
                if ( string.IsNullOrEmpty ( nbxSuccessUrl ) )
                    l.Add ( new Exception ( "'Success Url' setting not filled out'" ) );
    
                if ( string.IsNullOrEmpty ( nbxSuccessRedirectUrl ) )
                    l.Add ( new Exception ( "'Success Redirect Url' setting not filled out'" ) );
    
                if ( string.IsNullOrEmpty ( nbxCurrenceyCode ) )
                    l.Add ( new Exception ( "'Currencey Code' setting not filled out'" ) );
    
                return l;
    
            }
        }
    
    }
  • Martin Lingstuyl 202 posts 379 karma points
    Apr 06, 2012 @ 09:57
    Martin Lingstuyl
    0

    Hi Asif,

     

    It looks like you create a html form on the fly and auto-post it, right!?
    I thought Tim said that workflows happen in the background, but he probably meant the pre-set workflows. So a custom workflow can work with the record data as well as redirect the user to another page.

     

    Thanks a lot, I've downloaded the Development Manual and created a custom workflow. working with it now.

     

    Martin

Please Sign in or register to post replies

Write your reply to:

Draft