Situation: D7 Text field on a content type.

User enters something like: b52

I want it stored in the database as: B-52

I have a function that does the regex. I just don't know where to process the input before it goes in the database.

Don't want to install Field Validation or do any validation forcing a User to "correctly" format their own data. I just want to catch their input, modify it, and save it in the database as so.

What hook do I use and can it be done in the theme?

1 Answer 1


OK figured it out.

hook_node_presave() is what I want and it can only be called from a module I think.

Found the answer here: node_presave doesn't work

function nodepresave_node_presave($node){
  drupal_set_message('nodepresave DEBUG: PRESAVE Called');
  if ($node->type === 'vehicle') {
    drupal_set_message('nodepresave DEBUG: node->type === vehicle');

Your Answer

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

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