5

I am implementing a custom validator for WFFM, to do so I followed the Sitecore documentation: https://doc.sitecore.net/web_forms_for_marketers/working_with_actions_and_validations/validations/walkthrough_create_and_assign_a_custom_fieldtype_validator

Valdation field, located at: /sitecore/system/Modules/Web Forms for Marketers/Settings/Validation/Key validator Form designer - Valdation field

Code:

public class KeyValidator : FormCustomValidator
{
    public KeyValidator()
    {
        ServerValidate += OnKeyValidate;
    }

    private void OnKeyValidate(object source, ServerValidateEventArgs args)
    {
        // some validation here...
    }
}

Assigned to "Single-Line Text" field However the new custom validator does not appear in the form designer:

Form designer - Valdation field

0

1 Answer 1

1

Field type validator:

When you assign validations to a field, the changes you have made to the field affect all the forms on your website that use it. In addition to the default validations, you can also create your own custom field-type validations.

What you did, is the validation for the Field Type not for a specific form. You can create predefined validations which is documented here - https://doc.sitecore.net/web_forms_for_marketers/working_with_actions_and_validations/validations/set_up_and_create_a_formspecific_field_validation

Unfortunately this only allows you to put there regular expressions.

Suggested solution

I would create form verification which is called when the user submit the form.

enter image description here

After you created the new Form Verification item you can select this on the form.

enter image description here

The implementation should look like something like this:

namespace MyProject
{
    public class KeyValidator : WffmCheckAction
    {
        public override void Execute(ID formid, IEnumerable<ControlResult> fields, ActionCallContext actionCallContext = null)
        {
            // here is your validation
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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