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).
Make a folder (directory) inside the
sites/all/modules
calledquotetitlenotrequired
Inside the
sites/all/modules/quotetitlenotrequired
directory, create one file namedquotetitlenotrequired.info
and another file namedquotetitlenotrequired.module
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
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'; } }
After you've saved both files, go to
www.yoursite.com/?q=admin/build/modules
Scroll down and check the box next to the Quote Title Not Required module (it should be listed under "Other")
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...
:)
精彩评论