开发者

No title node in Drupal

I want to have a content type namely quote usign CCK. But quotes in general don't have a title. But since the title is a required field开发者_如何学编程, how can I avoid being putting the title while creating a new node.


Check out the Automatic Nodetitles module, which should facilitate what you're looking to do.


Another option is to alter the form whose ID is YOUR_CONTENT_TYPE_node_form. For instance, assuming your content type is quote, then the form ID you'd want to alter would be quote_node_form. Here's a complete module that will make the title text field that you'd normally see

  • Not required, and
  • Hidden

We'll name the module quotetitlenotrequired (it may look a little clunky, but you should always try to avoid using underscores while naming your modules).

  1. Make a folder (directory) inside the sites/all/modules called quotetitlenotrequired

  2. Inside the sites/all/modules/quotetitlenotrequired directory, create one file named quotetitlenotrequired.info and another file named quotetitlenotrequired.module

  3. Paste the following code inside the quotetitlenotrequired.info file:

    ; $Id$
    name = Quote Title Not Required
    description = Makes node titles not required for quotes.
    core = 6.x
  4. Paste the following code inside the quotetitlenotrequired.module file:

    <?php
    // $Id$
    
    /**
     * @file
     * Makes node titles not required for quotes.
     */
    
    /**
     * Implements hook_form_alter().
     */
    function quotetitlenotrequired_form_alter(&$form, &$form_state, $form_id) {
      if ($form_id == 'quote_node_form') {
        $form['title']['#required'] = FALSE;
        // Remove the next line if you still want the title field to be visible
        $form['title']['#type'] = 'hidden';
      }
    }
    
  5. After you've saved both files, go to www.yoursite.com/?q=admin/build/modules

  6. Scroll down and check the box next to the Quote Title Not Required module (it should be listed under "Other")

  7. Scroll all the way down and click Save configuration

Now, when you go to create a new quote, the title should no longer be required. And if you left the line there that says $form['title']['#type'] = 'hidden';, the whole title portion should no longer appear on the form.

Hope that helps...

:)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜