1

While implementing a custom login form, I need to show why login failed on submit action, for e.g. message like "no such user", "invalid credentials" etc. in Sitecore 9 Forms there is a field to provide general error message for all errors, but I want to provide custom messages. Is it possible?

2

You should start by creating a custom submit action: https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/sitecore_forms/setting_up_and_configuring/walkthrough_creating_a_custom_submit_action

In the definition of the submit action you can enter an error message..

If you create a submit action that validates the login, you could return false in that action and have your error message displayed. In case of a login you should never give details about why it failed. Ever. Your security officer should go berzerk if you do..

But to answer your question.. and suppose you have another form that you do want to have a message displayed based upon something decided in the code of the submit action.

You can do this.. a submit action is triggered and executed. If the execute method returns false, an error is added to the FormSubmitContext Error list. This error will get its message from the SubmitActionData.ErrorMessage. You can change that value in your code.. so in the execute method, change the value of SubmitActionData.ErrorMessage to your needs and return false. That should do it.

| improve this answer | |

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.