I created a custom content type with textfield called productID. Well all the data is imported and now he wants that field to be validated against a list of productId's. I have not imported the list if productID's yet so I can put them in a taxonomy, however how would I go about validating against this list so when they go to save the content type it returns false if not in the list and not allow them to save.

Thank you

  • Why use a text field at all? If the product ids will be in a vocabulary anyway just use a term reference field and make it required
    – Clive
    Aug 30, 2012 at 0:28
  • Because this was an after thought and I really don't want to reimport 90,000 nodes.
    – Brian
    Aug 30, 2012 at 0:44

2 Answers 2


First you should add a validation function to your form in your custom module , in hook_form_alter

function yourmodule_form_alter(&$form,$form_state,$form_id) {
  if($form_id == 'yourform_name') {

and after it you can everywhat you want in yourcustom validation function

function yourcustom_validate_function(&$from,&$form_state) {
  'your validation come here'
  if('not validate')
     form_set_error('yourfieldname',t('error message'));


I suggest you perform validation and get taxonomy with taxonomy_get_term_by_name,Its help you.

This links can help you more
drupal form_alter
custom drupal form validation1
custom drupal form validation2


If you are using feeds (http://drupal.org/project/feeds/) to import your data you can also use feeds tamper (http://drupal.org/project/feeds_tamper) to validate the data. Here is all the available option you have when using the feeds tamper (http://drupal.org/node/1246578)

  • The data has already been imported. I would now like to run a validation against it.
    – Brian
    Aug 30, 2012 at 0:45
  • This changes the original questions requirements quite a bit. After-the-fact bulk validation and 'on submit' validation are implemented in very different ways. This kind of bulk validation makes me think Views and Views Bulk Operations would be good starting points, whereas on-submit validation would be done with the Form API.
    – Citricguy
    Aug 30, 2012 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.