I have a custom content type, Picture, which has only a single required image field. Since this field is required, I thought that it should be impossible for users to save a node without uploading a file, but every once in awhile there is a node created that has no file uploaded.

Users have permission to create nodes of type Picture but not to edit them.

To try to troubleshoot this problem, I would like to record the user agent information (browser, etc.) of users when they create nodes of this content type. Is there a "standard" way to go about this?

I'm on Drupal 7 if it matters.

1 Answer 1


I would probably use a combination of hook_node_insert and watchdog (to keep UA info off of nodes and because it is really a logging exercise).

Example (this is totally untested and off the top of my head):

function MYMODULE_node_insert($node){
  if ($node->type == 'MY_NODE_TYPE') {
    // Check for the empty value however you want here.
    // e.g. Field API, EntityMetaDataWrapper, or whatever
    if (!isset($node->field_MY_IMAGE_FIELD[$node->language][0])) {
      $user_agent = $_SERVER['HTTP_USER_AGENT'];
      $account = $_GLOBALS['user'];
      $message = t('Empty image field created by !uid using !user_agent',
        array('!uid' => $account->uid, '!user_agent' => $user_agent));
      watchdog('MYMODULE', $message, WATCHDOG_NORMAL);

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.