validformbuilder icon indicating copy to clipboard operation
validformbuilder copied to clipboard

Allow more characters for string validation

Open kaphert opened this issue 9 years ago • 0 comments

Expected behavior

Characters like $ { } [ ] \ should be allowed by the VFORM_STRING, VFORM_TEXT, VFORM_HTML regex.

Actual behavior

Those characters are not allowed.

Steps to reproduce the behavior and a code example

$form = new ValidForm("form");

$chars = ['$','{','}','[',']','\\'];
foreach ($chars as $i => $char) {
    $form->addField($i, $char, ValidForm::VFORM_STRING, [], [], ['default' => $char]);
}

if ($form->isSubmitted() && $form->isValid()) {
    echo $form->valuesAsHtml();
} else {
    echo $form->toHtml();
}

Solution

Extend the regex with \$\{\}\[\]\\. This will solve it for these characters but tomorrow I want to have the British pound symbol, Cyrillic or Chinese in my editor. There should be an option to give a custom validator to a field so it is possible to allow these characters when needed. Or maybe even better to add a option to pass a validator class to the ValidForm object so you can overwrite the complete validation logic if you want.

$objForm = new ValidForm();
$objForm->setValidator(new MyCustomValidator());

kaphert avatar May 10 '17 13:05 kaphert