Copied to clipboard

Flag this post as spam?

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


  • Dominic Bush 10 posts 81 karma points
    Aug 06, 2016 @ 11:42
    Dominic Bush
    0

    Custom Forms workflow - How to handle failure?

    Hi,

    I have written a custom workflow based on this documentation that makes a REST call out to the GoToWebinar service API. All good so far.

    What I want to know is how to pass an error message back to the user if it has not been possible to make the call successfully for whatever reason?

    In the Execute method I am returning WorkflowExecutionStatus.Failed but from the user perspective the form seems to have been submitted correctly without error and the success message is displayed.

    How do I show a message that says something like, "Sorry, we were not able to register you for this webinar. Please try again later" in the event that the workflow has failed.

    Thanks, Dom.

  • Dominic Bush 10 posts 81 karma points
    Aug 12, 2016 @ 09:24
    Dominic Bush
    0

    Sorry to bump but it would be great if anyone had an idea about how to do this?

  • Theo Paraskevopoulos 33 posts 122 karma points
    Aug 12, 2016 @ 09:36
    Theo Paraskevopoulos
    0

    Hey Dominic

    I haven't tested it, but something like this should work:

    if (error) //your error condition
    {
        e.Form.MessageOnSubmit = "Your error message";
        return WorkflowExecutionStatus.Failed;
    }
    

    Obviously, this will only work if you don't send the user to a new page after submitting the form.

    Hope that helps

    /Theo

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Mar 26, 2020 @ 04:45
    Heather Floyd
    1

    I wish this would work - it would be an elegant solution. Unfortunately, at least in Umbraco v8.5.5 / Forms 8.3.2, setting this in a Workflow doesn't change what the visitor sees.

    I think the "MessageOnSubmit" is shown before any of the Workflows run. (See https://github.com/umbraco/Umbraco.Forms.Issues/issues/205) 😒

  • ivan valadares 3 posts 73 karma points
    Sep 04, 2018 @ 11:44
    ivan valadares
    0

    Did you solve the problem?

  • Comment author was deleted

    Mar 26, 2020 @ 07:32

    Workflows status doesn't have any impact... so .Failed or . Success doesn't do anything different...

    So if you have ideas please post on issues https://github.com/umbraco/Umbraco.Forms.Issues/issues/205

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Mar 26, 2020 @ 14:39
    Heather Floyd
    0

    I started a new issue since that one was closed. https://github.com/umbraco/Umbraco.Forms.Issues/issues/312

  • Comment author was deleted

    Mar 26, 2020 @ 08:10

    I think if you want to influence form submission (and show error messages) you need to hook into the event model

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Mar 26, 2020 @ 14:44
    Heather Floyd
    0

    Tim, Can you point me to the documentation for the Forms events? I didn't see events mentioned in the Forms > Developers docs.

  • Comment author was deleted

    Mar 26, 2020 @ 14:49

    Let me see if I can find a recent example, but you need to find the event on the forms controller

    http://www.nibble.be/?p=430

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Apr 01, 2020 @ 23:12
    Heather Floyd
    0

    Hi Tim,

    I took a look at your blog post example code. For v8 forms, I started "translating" it a bit...

    I believe this is how one adds events...

    public class Startup : IUserComposer
        {
            public void Compose(Composition composition)
            {
                composition.Components().Append<MyCustomFormsEvents>();
            }
        }
    

    And then...

    public class MyCustomFormsEvents: IComponent
        {
            #region Implementation of IComponent
    
            public void Initialize()
            {
                FormRenderController.FormValidate += FormRenderController_FormValidate;
            }
    
            public void Terminate()
            {
            }
    
            #endregion
    }
    

    BUT... I can't find FormRenderController in any of the new Forms Assemblies...

  • Yevhenii_Koliesnik 3 posts 73 karma points
    Apr 03, 2020 @ 09:05
    Yevhenii_Koliesnik
    0
         Umbraco.Forms.Web.Controllers.UmbracoFormsController.FormValidate += UmbracoFormsController_FormValidate;
        }
    
        private void UmbracoFormsController_FormValidate(object sender, Umbraco.Forms.Mvc.FormValidationEventArgs e)
        {
            throw new System.NotImplementedException();
        }
    
  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Apr 03, 2020 @ 18:41
    Heather Floyd
    0

    Thanks, Yevhenii, that was what I needed :-)

    I've now got all my code working.

    https://github.com/hfloyd/Dragonfly.Umbraco8FormsMembers

  • Yevhenii_Koliesnik 3 posts 73 karma points
    Apr 03, 2020 @ 09:49
    Yevhenii_Koliesnik
    0

    As posted above Heather Floyd created issue on which still is "Open". I use some api in workflow and want to show error on form if something wrong. Like hot fix (it's not good but works for me) i use: System.Web.HttpContext.Current.Response.AddHeader("isError", "true");

      public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            var model = new NewsLetterModel();
            var list = new List<FieldMapping>();
    
            if (!string.IsNullOrEmpty(Fields))
                list = JsonConvert.DeserializeObject<IEnumerable<FieldMapping>>(Fields).ToList();
    
            if (list.Any())
            {
                foreach (var fieldMapping in list)
                {
                    try
                    {
                        var alias = fieldMapping.Alias;
    
                        if (string.IsNullOrEmpty(fieldMapping.Alias))
                        {
                            continue;
                        }
    
                        var value = fieldMapping.StaticValue;
    
                        if (!string.IsNullOrEmpty(fieldMapping.Value))
                        {
                            value = string.IsNullOrEmpty(
                                    record.RecordFields[new Guid(fieldMapping.Value)].ValuesAsString(false))
                                    ? fieldMapping.StaticValue
                                    : record.RecordFields[new Guid(fieldMapping.Value)].ValuesAsString(false);
                        }
    
    
                        var property = model.GetType().GetProperty(fieldMapping.Alias);
    
                        //LogHelper.Warn<ContactUsModel>($"Start name:{alias} value:{value}");
                        if (property == null)
                        {
                            //LogHelper.Warn<ContactUsModel>($"No property found {alias} ");
                            continue;
                        }
                        else
                        {
                            var t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
                            var safeValue = (value == null) ? null : Convert.ChangeType(value, t);
                            property.SetValue(model, safeValue, null);
                        }
    
                        var newsLetterService = DependencyResolver.Current.GetService<IMohEmailNewsLetterService>();
                        newsLetterService.CreateOrUpdateContact(model);
    
                        // TODO: remove it just for test!!!!
                        throw new Exception("Test");
                    }
                    catch (Exception exception)
                    {
                        //LogHelper.Error<ContactUsModel>($"Workflow Mapping Error:{JsonConvert.SerializeObject(list)}", exception);
                        //return WorkflowExecutionStatus.Failed;
    
                        System.Web.HttpContext.Current.Response.AddHeader("isError", "true");
    
                       // throw;
                    }
                }
    

    I use ajax update for form:

    function onSubmitNewsLetter(token) {
        $.ajax({
            url: $form.attr('action'),
            type: 'POST',
            cache: false,
            data: $form.serialize(),
            success: function (result, textStatus, request) {
                if (request.getResponseHeader('isError') == true) {
                    var errorMessage = "call to tech service 5300";
                    $('.subscribe-form .umbraco-forms-page').html(errorMessage);
                }
                else {
                    $('.subscribe-form .umbraco-forms-page').addClass('success');
                    var thankYouMessage = $(result).find('.newsletter-form-message').html();
                    $('.subscribe-form .umbraco-forms-page').html(thankYouMessage);
                }
            }
        });
    }
    
  • lori ryan 239 posts 573 karma points
    Jan 25, 2021 @ 14:02
    lori ryan
    0

    How did you get your form to use the ajax function?

Please Sign in or register to post replies

Write your reply to:

Draft