Prevent the user from creating more than one node (of a certain type)

Avatar-eric-london
Created by Eric.London on 2008-04-16
Tags:
New Comment
 
In certain situations you may want to prevent the user from creating more than one node (of a certain type). This can be accomplished using the hook_nodeapi...

<?php
function MYMODULE_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  // ...some code...
  if ($node->type=='YOURNODETYPE' && 'op'=='prepare' && $_REQUEST['q']=='node/add/YOURNODETYPE') {
    $sql = "select nid from {node} where type='YOURNODETYPE' and uid='%d' and status='1'";
    $resource = db_query($sql, db_escape_string($GLOBALS['user']->uid));
    $result = db_result($resource);
    if ($result) drupal_goto('SOMELOCATION');
  }
  // ...some code...
?>

NOTE: the above code will prevent the user from adding another node by redirecting them away from the node/add page

Comments

 
  • drupal 6
    Created by Anonymous on 2009-08-22
    Hi there,

    I was wondering if much would need to be changed to implement this in Drupal 6?

    It's just what I needed! Thanks.

    Carolyn.