Validation problem

Discuss PivotX 2.0.x extensions here, and view extensions that are available for download.

Validation problem

Postby Gooly » Sun Sep 18, 2011 5:34 pm

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.
That's the trouble with reality,
it's taken far too seriously
User avatar
Gooly
 
Posts: 77
Joined: Thu Nov 19, 2009 5:52 pm
Location: Lat 52° 4' 11.4874" Lon 4° 17' 28.001"

Re: Validation problem

Postby hansfn » Sun Sep 18, 2011 10:47 pm

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.)
hansfn
Developer
 
Posts: 3280
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Validation problem

Postby Gooly » Mon Sep 19, 2011 7:20 am

Thanks Hans, it did the trick perfectly.
That's the trouble with reality,
it's taken far too seriously
User avatar
Gooly
 
Posts: 77
Joined: Thu Nov 19, 2009 5:52 pm
Location: Lat 52° 4' 11.4874" Lon 4° 17' 28.001"


Return to 2.x Extensions

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron