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.
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 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...
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);
}
}
});
}
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.
Sorry to bump but it would be great if anyone had an idea about how to do this?
Hey Dominic
I haven't tested it, but something like this should work:
Obviously, this will only work if you don't send the user to a new page after submitting the form.
Hope that helps
/Theo
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) 😒
Did you solve the problem?
Comment author was deleted
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
I started a new issue since that one was closed. https://github.com/umbraco/Umbraco.Forms.Issues/issues/312
Comment author was deleted
I think if you want to influence form submission (and show error messages) you need to hook into the event model
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
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
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...
And then...
BUT... I can't find
FormRenderController
in any of the new Forms Assemblies...Thanks, Yevhenii, that was what I needed :-)
I've now got all my code working.
https://github.com/hfloyd/Dragonfly.Umbraco8FormsMembers
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");
I use ajax update for form:
How did you get your form to use the ajax function?
is working on a reply...