lisardo
lisardo

Reputation: 1454

powermail: custom validator without option mandatory

I defined a custom validator which works as expected when the form field ist filled with a value. But when the form field is left empty the custom validator is not called and the field is not validated.

When i additionally activate the option "mandatory" I could prevent that the form is sent with an empty value but this is not possible in my case because the field must not be mandatory.

More precisely:

Checkbox Newsletter: when not checked the field "email" is not needed and therefore not mandatory. When checked the field "email" is needed and should therefore be mandatory and validated by my custom validator which checks if the address is in the database already.

My Question:

Upvotes: 0

Views: 412

Answers (1)

uocnma
uocnma

Reputation: 1

You could try powermail_cond. This extension enables you to show or hide fields depending on the state of other form fields. So you would create a second field "email" without validation and mandatory flag. Then via powermail_cond you create the following rules

  1. Show field "email-optional" when checkbox is not checked
  2. Hide field "email-mandatory-with-validation" when checkbox is not checked
  3. Hide field "email-optional" when checkbox is checked
  4. Show field "email-mandatory-with-validation" when checkbox is checked

This should work with powermail_cond 7.4.

Upvotes: 0

Related Questions