Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Is 'valid_string' Broken?
  • I can't get 'valid_string' validation to work. I have a model with a 'surname' field. In this field - just for testing purposes - I want the user to be able to type only alpha characters, and spaces. The validation is specified in the model like this:
    <?php
    
    class Model_Client extends Orm\Model &#123;
     
     protected static $_properties = array(
      'id',
      'created_at',
      'updated_at',
      'given_names' => array(
       'type' => 'string',
       'label' => 'Given Names',
       'validation' => array('trim','strip_tags','required'),
      ),
      'surname' => array(
       'type' => 'string',
       'label' => 'Surname',
       'validation' => array('trim','strip_tags','required', 'valid_string'=>array('alpha','spaces')),
      ),
      'birthdate',
      'birthcountry'
     );
     
     protected static $_observers = array(
      'Orm\Observer_CreatedAt' => array('before_insert'),
      'Orm\Observer_UpdatedAt' => array('before_save'),
      'Orm\Observer_Validation' => array('before_save'),
     );
     
    }
    
    Unfortunately, the validation for the surname field *always* fails, as soon as I put anything else in the 'valid_string' array, apart from 'alpha'. It works like this: (1) Using array('alpha') only: works as expected (2) Using array('alpha', *): if anything else is added after 'alpha' (such as 'spaces', or 'dashes'), then it ignores whatever is added afterwards, and validation only works if there are only alpha characters - that is, if I add a space (or a dash), even if I specified that this is be allowed by using 'spaces' (or 'dashes'), then validation fails (3) Using array(*,'alpha'): if anything is added before 'alpha', then validation *always* fails, even if the field contains only alpha characters. Is this a bug, or am I doing something obviously stupid?
  • Cross post with issue tracker: https://github.com/fuel/core/issues/555 - closing this to avoid 2 separate discussions.
This discussion has been closed.
All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion