0

I want to check if the entered value is already in the database or not. If it is, I want to stop creating the node, and show a message telling the users to change that value; if that value is not found in the database, the user should be able to create the node.

What is the correct function to call to stop the creation process?
How do I check if the field value is already in the database?

1 Answer 1

2
  1. You should use hook_node_validate This allows you to return error on the specific field that fails. e.g.

    if($query->rowCount() > 0) {
      form_set_error('machine_name', t('There already exists another node with same machine name - machine name has to be unique.'));
      // where machine_name is the field in this example
    }
    
  2. You wanna check database if value exists. Can you elaborate exactly what you wanna check? Is it to ensure a specific field only contains unique values?

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.