Formidable icon indicating copy to clipboard operation
Formidable copied to clipboard

Input type="number" constraint validation

Open NicolasRoehm opened this issue 4 years ago • 0 comments

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;

NicolasRoehm avatar Mar 13 '20 10:03 NicolasRoehm