How to avoid submitting a form when creating a new content, depending on some criteria? Let's suppose I have a content type Person, and I don't want the field Name to contain the text AAA.

What would be the best way of avoid submitting the form if that happens?

For example:
- Hiding the Save button
- Submitting it, but return to the same page with that field marked as red, or just show a message...

This is just an example. I'm asking it because sometimes I need to do a query to the database and see if some records exist, or something like that...

Edit:
I have edited the template.php file under the theme folder I'm using, and I have added the functions:


theme_theme()
theme_formId($form)


In the 2nd function, I've modified the form to see Drupal is calling this function, and yes, it works...

Then I did the following in the 2nd function:

$form['#validate'] = array('my_validate_function');

and under my_validate_function($form, &amp;$form_state) I just wrote form_set_error('', t('Testing...')); and nothing seems to be happening: I can still create a new content without problems :(

What am I missing here?
You can add validation callbacks to any form in Drupal using the Form API. Specifically, you can use hook_form_alter to add a validation callback to the $form['#validate'] element.