1

Hi we need to validate date in web forms for marketers, should we make a custom field or override the script. Usually,i override the existing validation like date-picker field and etc and it works.

We need to validate date-box to display date from 21 years ago until 10 years ago. Here is date-box script: Date-box script

could you give any solution or reference link? thanks

2

You haven't said which version of Sitecore / WFFM you are using but you should be able to create a custom field validator to validate the date like so (obviously you would need to add your own logic here):

public class DateInFutureValidator : FormCustomValidator
{
 public DateInFutureValidator()
    {
      this.ServerValidate += this.OnDateValidate;
    }
    private void OnDateValidate(object source, ServerValidateEventArgs args)
    {
      DateTime time = Sitecore.DateUtil.IsoDateToDateTime(args.Value).Date;
      if (time >= DateTime.UtcNow)
      {
        args.IsValid = true;
        return;
      }
      args.IsValid = false;
    }
}

more info here: https://doc.sitecore.net/web_forms_for_marketers/working_with_actions_and_validations/validations/walkthrough_create_and_assign_a_custom_fieldtype_validator

and here: https://jonathanrobbins.co.uk/2015/06/09/sitecore-webforms-for-marketers-mime-type-sniffer-custom-field-validator/

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