background image
Eric's picture

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

drupal 6

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.

Eric's picture

new blog entry