Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Validating a Unique Filed
  • Hi, I'm having a little trouble with validating fields for uniqueness in the db. I've followed the tutorials but I guess I'm missing something. I'm getting this error on my form: Notice: Invalid rule "unique" passed to Validation, not used. in (unknown) [(unknown)]: add_rule My code is at http://scrp.at/aEj Thanks...
  • You need to add Myvalidation as a callable to the Validation instance, otherwise there's no way the Validation could ever find the rule.
    $fieldset->validation()->add_callable('Myvalidation');
    

    Or add the rule to your own Validation class extension in which case it'll always be part of the available rules.
  • @Jelmer did what you said <code>
    if ($fs = Fieldset::instance(get_class($town)))
    {
    echo $fs->show_errors();
    } $fieldset = Fieldset::factory('status')->add_model($status, null, null);
    $fieldset->validation()->add_callable('Myvalidation');
    $fieldset->validation()->add_field('name', 'Status Name')
    ->addRule('unique'); $fieldset->validation()->set_message('unique', 'A record for :name already exists in the database.'); $fieldset->add('name', 'Status Name'), array('type' => 'text'));
    $fieldset->add('submit', ' ', array('value' => 'Submit', 'type' => 'submit')); $fieldset->populate($status, TRUE); echo $fieldset->build(); </code> But I'm still getting the error: Notice: Invalid rule "unique" passed to Validation, not used. in (unknown) [(unknown)]: add_rule any ideas
    Thanks... UPDATE: The error was happening because I had it in my Model validation rules. Removed it from there but now I get a SQL Error when trying to insert a duplicate. So, obviously the validation rule is not running.

Howdy, Stranger!

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

In this Discussion