Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input type="number" constraint validation #59

Open
NicolasRoehm opened this issue Mar 13, 2020 · 0 comments
Open

Input type="number" constraint validation #59

NicolasRoehm opened this issue Mar 13, 2020 · 0 comments

Comments

@NicolasRoehm
Copy link
Contributor

NicolasRoehm commented Mar 13, 2020

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant