nliautaud / p01contact

Create contact forms by writing simple tags. Also a plugin for GetSimple and Pico CMS.
MIT License
16 stars 15 forks source link

Use regex patterns instead of blacklist/whitelist #19

Open nliautaud opened 6 years ago

nliautaud commented 6 years ago

The "fields lists" settings would be replaced by "fields rules" where blacklist/whitelist is renamed to "should match" and "shouldn't match" and the content would be a regex capture group, like :

first|second|third

The code would be something like

$rule = array_filter($this->form->config('rules'), function($rule) {
    return $rule->field_type == $this->type;
});
if (!$rule || empty($rule->regex)) return;
$pattern = "`({$rule->regex})`";
$found = preg_match($pattern, $this->value);
return ($found && $rule->not) || (!$found && !$rule->not);

Instead of

https://github.com/nliautaud/p01contact/blob/46250518568fe07a97206b68a8c874ad9cac1adb/p01-contact/src/P01contact_Field.php#L161-L180