0

Using sc8.u3 with WFFM 8.2u3

I'm encrypting form data on submit. When there is an exception, I would like to show the error message but here, it always shows the success message.

public override void InsertFormData(FormData form)
        {
            Assert.ArgumentNotNull(form, "form");
            Assert.ArgumentNotNull(form.Fields, "form.Fields");

            try
            {
                form.Fields = EncryptFields(form.Fields);

                if (form.Fields != null)
                {
                    base.InsertFormData(form);
                }
            }
            catch(Exception ex) 
            {
                Log.Error("Exception: " + ex.Message, this);
                throw;              
            }
}
  • Which type of error you expect to catch? And could you provide your error from Sitecore log file? – Andrei Paliakou Nov 23 '17 at 8:44
  • @AndreiPaliakou. There are no errors in log file, and I'm not sure of what exceotions may occur. I just want to show the error message to end user when there is an exception. In current case, it always shows success message – Qwerty Nov 23 '17 at 8:46
  • @Qwerty you are doing everything right. Sitecore WFFM actions work in next way: if any exception is thrown then error message on is displayed. You can configure error messages on "Error messages" tab of "Save actions" dialog. – Anton Nov 23 '17 at 16:22
2

If you want to return your error message to user, you need to have ErrorMessage text field on your form,then get FormData form, find this ErrorMessage field and add your error message there. Also you need to wrap your logic:

public override void InsertFormData(FormData form)
        {
            Assert.ArgumentNotNull(form, "form");
            Assert.ArgumentNotNull(form.Fields, "form.Fields");

            try
            {
                form.Fields = EncryptFields(form.Fields);

                if (form.Fields != null)
                {
                    base.InsertFormData(form);
                }
            }
            catch(Exception ex) 
            {
                Log.Error("Exception: " + ex.Message, this);
                throw new Exception("Error Message");              
            }
}

If it not help, try to do step by step this suggestion

  • Even if i read the message from the text field, Sitecore is ignoring that exception and considers form submit as success. So it hides the form and shows the success message. Right? – Qwerty Nov 23 '17 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.