Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
'valid_string' rule is not correctly Fieldset add()
  • Hi,


    Code:

    $fieldset = Fieldset::forge('item');
    $fieldset->add(
    'price',
    'Price',
    array('type' => 'text'),
    array(
    array('required'),
    array('valid_string' => array('numeric')),
    )
    );
    This code is not work... Other rules (ex. valid_email) are correctly.

    now I am using add_rule() instead.
    Don't use 'valid_string' in Fieldset add()?
  • valid_string supports multiple values, so it should be

    array('valid_string' => array(array('numeric')))

  • thanks for reply,

    I tried code:

    $fieldset->add(
    'price',
    'Price',
    array('type' => 'text),
    array(
    array('required'),
    array('valid_string' => array(array('numeric')))
    )
    );

    Get Notice...

    Fuel\Core\PhpErrorException [ Notice ]: Array to string conversion

    COREPATH/classes/validation.php @ line 452


    Probably, Fieldset_Field will be problem (bug??).
    rules get from func_get_args(), NO received keys.

    (use 1.6/master)
    core/classes/fieldset/field.php:131
    call_user_func_array(array($this, 'add_rule'), (array) $rule);

    and Dump $callback and func_get_args() at add_rule method,
    could not found 'valid_string' key.


    Variable #1:($callback)
      (Array, 1 element) ↵
         0 (Array, 1 element) ↵
             0 (String): "numeric" (7 characters)


    Variable #2:(func_get_args())
      (Array, 1 element) ↵
         0 (Array, 1 element) ↵
             0 (Array, 1 element) ↵
                 0 (String): "numeric" (7 characters)

    Therefore, _validation_valid_string is not called.


  • HarroHarro
    Accepted Answer
    Misread your question.

    The correct syntax is:

    $fieldset->add('fullname', __('users.form.fullname'), array(), array('required', array('valid_string', array('alpha','spaces'))));


    So the entry in the rules array is either a string or an array. In either case, the array key isn't used. If it is an array, the first element is the rule, the second element the optional parameters for the rule. The parameters entry can be either be a value (string, integer) or an array of values, like in this example.
  • Thank you so much!!
    (and I'm sorry my words were not clear...)

Howdy, Stranger!

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

In this Discussion