Page 1 of 1

Validation problem

PostPosted: Sun Sep 18, 2011 5:34 pm
by Gooly
When testing my extension, I have an issue with the validation of the form fields in the extension configuration panel in the PivotX backend.

It concernes a text field, with an optional content. So empty is allowed.
When you add a value to the field, everything works fine, but as soon as you empty the field (removing the content) this results in a validation error, and of course that is not what I want, since empty must be accepted too.

The extension functionality is not affected. If you ignore the errormessage, everything works as it should. Also, when you refresh the admin page, the field comes back empty, without content and without error.

The code block for the field, including the validation line is:

Code: Select all
      $form->add( array(
        'type' => 'text',
        'size' => 50,
        'name' => "url".$i,
        'label' => "Link url ".$i,
        'validation' => 'ifany|string|maxlen=50'
      ));

(The $i variables in name and label are there because the field is part of a for loop)

It's my first extension, so probably I'm missing something, but I have no clue what.

Re: Validation problem

PostPosted: Sun Sep 18, 2011 10:47 pm
by hansfn
The problem is that you ask for a string (ref 'ifany|string|maxlen=50') and the empty string isn't accepted. Just remove the string requirement. It doesn't really make much sense since all input from a form is a string for PHP. (This isn't your fault. You have probably copied the usage from the PivotX core.)

Re: Validation problem

PostPosted: Mon Sep 19, 2011 7:20 am
by Gooly
Thanks Hans, it did the trick perfectly.