umbraco / Umbraco.Forms.Issues

Public issue tracker for Umbraco Forms
30 stars 0 forks source link

Graceful validation of fields with placeholders #1132

Closed bjarnef closed 10 months ago

bjarnef commented 10 months ago

I noticed on one our Umbraco Cloud project, a multi-site / multi-language solutions, that a contact form failed rendering on the German site, but not on other sites.

image

image

First I though it was because of the German characters in error messages like ü, ä and ö, but after further investigation I found it was due a syntax error in the error message.

image

I wonder if we could either have some regex validation here in case the validation message contains {0 or 0} and maybe even {{0}}?

or some graceful validation, when rendering the form. E.g. log the error message, but don't fail rendering the entire form. It could eventually just fallback to default error message or just use the raw string, so it frontend one would just see Bitte überprüfen Sie 0} instead of the correct message Bitte überprüfen Sie {0} where {0} is replaced with the actual field name.

I think this is less critical as content editors sometimes make mistakes and often not familiar with {0} placeholder.

The description below "Mandatory Error Message" and "Invalid Error Message" can eventually mention this as well, because if one deleted it, it can be difficult to know it's an option to add.

Forms v12.1.2 Umbraco v12.2.0


This item has been added to our backlog AB#36127

bjarnef commented 10 months ago

Maybe something like this: https://stackoverflow.com/a/36642556

public static class StringExtensions
{
    public static bool HasPlaceholder(this string s)
    {
        return Regex.IsMatch(s, "{\\d+}");
    }
}

But there is of course a chance one of the placeholders can be incorrect formatted. I haven't checked of Forms only use a single value as placeholder and if it is possible to extend added more placeholder values.

image

dtng95 commented 10 months ago

Hi @bjarnef, Thank you for reporting this issue. A fix has been made and will be included in the next release/patch

AndyButland commented 10 months ago

We'll include a basic check for a valid format string, as expected for these validation messages, with the next round of patch releases for the versions indicated.