Hi,
I got this module that works with taxonomies: I want to prevent terms that do not follow certain rules to be added to the vocabulary. I am implementing the hook_taxonomy to follow changes in the taxonomies, and in the insert case I check the term is correct, and if not so a fire a form_set_error. So far so good except that the term is being inserted into the database all the same!!!
So what can I do to prevent the term of being added when it fails my check?
The term is being inserted through the drupal's taxonomy form (taxonomy_form_term). So anyway I can add a validation to that form, from MY custom module? Is that possible ?
The only ways I can think of solving this is delete the term as soon as is being installed ... or hack the default taxonomy module to made it follow my restrictions. And both ways seem hackish/ugly enough to me.
So any idea, please?
Comments
You could implement
You could implement hook_form_alter(), look form the form id used to add taxonomy terms and add a validation function to the form.
But how to add the validation to the form, please ?
Thanks, that sounds like what I am looking for, still there is something I do not get: how to add the validation to the form? The only way to validate that I know is implementing hook_validation, that I though it was for nodes only. And even if it can work for taxonomies too, how can I tell it to validate the taxonomy terms form? It is not supposed to validate the form from the current module you are implementing? Even if I know the ID of the form I want to validate, I see no way to pass that id to the function.
Could someone clarify how to call that function and from where? Is there any example code/module I could have a look at to see how it is done?
You want code along these
You want code along these lines
Thanks
Thanks, that worked perfectly :-)