Search code examples
c#sitecoresitecore6sitecore8web-forms-for-marketers

Web Form for Marketers Custom Submit Action Error Message


I created new Submit Action for my WFFM form that inherits from WffmCheckAction class, which basically do a server side validation in case the client side validation is bypassed. The custom class that i created for this submit action looks like below:

public class EmailValidation : WffmCheckAction 
{
    public override void Execute(Sitecore.Data.ID formid, IEnumerable<ControlResult> fields, ActionCallContext actionCallContext = null)
    {
        ControlResult emailField = fields.FirstOrDefault<ControlResult>(f => f.FieldName.ToLowerInvariant().Trim().Equals(Constant.Cms.WFFM.Fields.Email.ToLowerInvariant()));

        if (emailField == null) //field not found.
            return;

        var emailVal = emailField.Value;
        if (emailVal != null && !string.IsNullOrEmpty(emailVal.ToString()))
        {
            if (!IsValidEmail(emailVal.ToString()))
            {
                throw new ArgumentException("Invalid Email Address");
            }
        }
    }

    bool IsValidEmail(string email)
    {
        try
        {
            var addr = new System.Net.Mail.MailAddress(email);
            return true;
        }
        catch
        {
            return false;
        }
    }
}

On sitecore 6.5, if email is not valid (IsValidEmail return false), Error message "Invalid Email Address" will be displayed in the form. After upgrading to sitecore 8.1 using Web Form For Marketers 8.1 rev 160523, I will instead get the default Save Action Failed Message, which in my case is "We experienced a technical difficulty while processing your request. Your data may not have been correctly saved." I have tried updating the error message in the Form Verification enter image description here

but I'm still getting the default error message. I suspect that with the upgrade, they have changed the behavior, and because I threw an ArgumentException, WFFM treats it as an error and displaying the default message instead. How do I display the custom message using the custom Submit Action ?


Solution

  • It is confirmed as Sitecore bug. Reference number for the patch is 78434.