Copied to clipboard

Flag this post as spam?

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

  • Nathan Rogan 18 posts 179 karma points
    Sep 06, 2021 @ 11:45
    Nathan Rogan

    Forms validation check / helper

    I need to add a custom class to a forms field if validation fails.

    This post is exactly what I need but it does not work -

    CMS: 8.14.4 Forms: 8.7.6

    @functions {
    public bool HasErrors(string fieldId) {
        if (ViewData.ModelState.ContainsKey(fieldId)) {
            return ViewData.ModelState[fieldId].Errors.Any();
        } else {
            return false;
    public string ValidStateClass(string fieldId) {
        var klass = "";
        if (HasErrors(fieldId)) {
            klass = "invalid";
        return klass;



    Does anyone know how to fix or have an alternative solution?


Please Sign in or register to post replies

Write your reply to: