Hi, I need to create script for automatic node title creation (9 number string) for particular content type, for now using automatic node title module, and have this code

$random1 = rand(100000000, 999999999);
$random2 = rand(100000000, 999999999);
$total = round(($random1 + $random2) / 2);
echo $total;

I know, that probability that this number would be repeating is almost none, but is there a way how to compare it with existing node titles for duplicity?

+ is it needed to have this module for this simple task? maybe page-node-edit.tpl.php could somehow handle this if configured properly with condition regarding node type (unfortunately this is not working in D6 for me.. http://drupal.org/node/104316#comment-693907)
+ I need to hide title field in edit node page of this node type, using auto node title have the option for hiding only when creating a new title, and it is not this situation, this number, even random at the beginning, can't be changed later.

Many thanx

Zdenek

Comments

savmac’s picture

Hi Zdenek,
Thanks for the code snippet, this is exactly what I need.
I would also like it to never change once created though. When I edit the node with the random title, I am unable to manually change the title, but the code runs again upon saving and a new random title is generated.
I am just starting to learn php so I don't know how to do it but could you add to the code to check first for an existing title? If title exists then do nothing, if no title exists then generate random number? This would essentially keep the random title static once it is created right?
Thanks again, Scott

Denys Babenko’s picture

Very handy, thanks