Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Validation and checkbox
  • hello anybody got validation working with checkboxes in form? I tried the rule "required", tried the "match_value",0 and 1
    not working Thanks Chris
  • oh. I did not put any value for this checkbox.
    Now this works. Thanks a lot!
  • Yes, it's working for me but without the match stuff. Here's code snippets from a test form that I created. In the controller:
    $form = Fieldset::factory('form_example')->add_model('Model_Mexamples', $example_id, 'set_form_fields_example');
    ...
    if ($form->validation()->run() == TRUE)
    

    In the model:
    ...
    public static function set_form_fields_example(Fieldset $form, $example_id = null)
    {
    ...
      // Checkboxes
      $form->add('checkbox_id',
       'Checkbox Test',
       array(
        'type' => 'checkbox',
        'options' => self::get_checkbox_options(),
        'id' => 'checkbox-test',
        'class' => 'checkbox-vertical',
        'title' => 'Select a checkbox widget',
        'value' => empty($examples) ? '' : $examples['checkbox_ids'],
       ),
       array(
        array('required'),
       )
      );
    ...
    }
    

Howdy, Stranger!

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

In this Discussion