Formidable
Formidable copied to clipboard
Input type="number" constraint validation
Hi @Gregwar, It seems that constraint acts weird in some cases, as you mentioned here.
When I set the following fields to 0
and submit the form :
- The
text
input throw the desired error (greater than zero) - The
number
input does not throw this error
HTML
<form>
<input type="text" name="items_per_page_1">
<input type="number" name="items_per_page_2">
<!-- ... -->
</form>
PHP
$form = new Gregwar\Formidable\Form('forms/myform.html');
$form->addConstraint('items_per_page_1', function($value)
{
if (!is_numeric($value))
return 'NUMERIC_ONLY';
if ((int)$value <= 0)
return 'GREATER_THAN_ZERO';
});
$form->addConstraint('items_per_page_2', function($value) { /* Same constraint */ });
echo $form;