Copied to clipboard

Flag this post as spam?

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


  • dev-thandabantu 41 posts 321 karma points
    Sep 11, 2022 @ 14:47
    dev-thandabantu
    0

    Umbraco Forms: in-code (custom) validation

    Hi,

    I have a registration form. I have added custom workflow to the form. Custom workflow checks if user input is valid. If not valid, I would like to display a validation message e.g "Invalid input. Contact admin".

    Here is sample code:

    try
    {
        if(ExistsInDatabase)
        {
            //do something
        }
        else
        {
            //show validation message "Input does not exist in DB
    
        }
    }
    catch (Exception)
    {
        return WorkflowExecutionStatus.Failed;
    }
    return WorkflowExecutionStatus.Completed;
    

    How do I achieve this? Thanks.

    NB: I don't think I can implement validation on the form itself in the backoffice because the validation involves checking the DB using EF Core.

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 11, 2022 @ 21:27
    Marc Goodson
    100

    Hi dev-thandabantu

    Would you be able to handle the serverside validation notification to do your check when the form is submitted?

    https://our.umbraco.com/documentation/Add-ons/UmbracoForms/Developer/Extending/Adding-an-Event-Handler#adding-a-server-side-notification-handlers-to-umbraco-forms

    Workflow steps are generally for custom actions after the form is successful submitted and validation is complete...

    Regards

    Marc

  • dev-thandabantu 41 posts 321 karma points
    Sep 12, 2022 @ 06:06
    dev-thandabantu
    1

    Thanks Marc! Yes, I am able to do the custom validation. I just wasn't sure what to do when the validation fails. Thank you for pointing me in the right direction and for pointing out that custom workflows are generally for actions after successful submission and validation.

    I am going to implement the validation first then. Thank you.

Please Sign in or register to post replies

Write your reply to:

Draft