Posted by DrupalDan on January 14, 2013 at 5:59pm
Hello,
I got a problem in hiding the title of node forms for real. Earlier to do so I tried the module "exclude node title" and implement a hook_form_alter in the template file, and both methods work great to hide the title from the node form. But recently I found out when the form reloads if required fields are not filled out the title, like "Create Article", can't be hidden, and neither of the above approaches can fix this. I'm completely lost and don't know how to deal with this. Can anyone please give me some clue? Thanks!
Comments
Are you try putting in your
Are you try putting this in your hook_form_alter:
<?php$form['title']['#required'] = FALSE;
$form['title']['#access'] = FALSE;
?>
still not working
Hi drupso, thank you very much for your response. I could really, really use some help.
My orginal hook_form_alter in the template is like this:
<?phpfunction mytheme_form_test_node_form_alter(&$form, &$form_state) {
drupal_set_title('');
?>
Please correct me if I'm wrong, I put the codes in there as follows,
<?phpfunction mytheme_form_test_node_form_alter(&$form, &$form_state) {
drupal_set_title('');
$form['title']['#required'] = FALSE;
$form['title']['#access'] = FALSE;
}
?>
And that's not working. Did I get it wrong?
Eager to hear your thought. Thanks!
=-=
I thought that hook form alters go into custom modules and don't begin with the name of the theme but with the id of form being hooked?
re
Hi VM, good to hear from you again. Do you mean I need to have a custom module for this? cause that's not how I did it; I just put that hook form alters in the template.php. As to the name, the "mytheme" part is just for example; I use my real theme name in the actual codes I put there. And the hook works great to hide the "Create Test" as far as the page is not reloaded for required fields; once the page got reloaded, "Create Test" would show. As to adding the form id, it's a little beyond me actually. Could you please tell me how to do it? I just went to see the source and found that the form id is "test-node-form". Thank you.
Well, if you want is hide
Well, if you want is hide "Create test" text, forget my first answer. Those lines allow you hide Title field in your form and set it as not required. If you want is hide "Create test" you can do quickly with CSS. Inspect it with Firebug or Chrome inspector to get in what CSS class is inside (f.e .page-title or similar). Then you can add in some of your CSS files in your theme enabled this:
.page-node-add .page-title{
display:none;
}
This hide Create {content-type} text in all node add forms. If you want hide this title only in "Test" content type, then you have to add this instead in your CSS:
.page-node-add-test .page-title{
display:none;
}
NOTE : .page-node-add or .page-node-add-test is a class CSS injected in your body HTML tag
re
@drupso, thanks for your response in detail. Unforunately, I just tried to add it in my style.css but that's not working. Does this css method apply to D7? Yes, I want to hide or even remove the title "Create Test", from both the page and the browser top left corner, whether the page reloads or not. But if I do it using css I can only hide it from the page but not the page title in the browser bar.
=-=
while it may work in template php the best practice is to create a custom module when utilizing hooks.
re
I also found something. When the page or the node form loads for the first time, the title on the browser (the top left corner) shows my site name | slogan (I guess that's because of the hook working), but when it got reloaded due to the required fields the title at that corner changes into something like the Create Test | site name, along with the h2 title in the content jumping out. Does that mean anything?
Well in this case, try to
Well in this case, try to test this code, creating a new module or reusing form alter:
<?php
function YOUR_CUSTOM_MODULE_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'test_node_form'){
drupal_set_title('');
$form['#validate'][1] = 'test_validate'; //we add an extra validation function that reset page title
}
}
function test_validate($form, &$form_state){
drupal_set_title('');
}
?>
With this, we reset Page title when create and validate a test node.
Regards
it works!!!
Hi drupso, I just tried it by adding the codes in the template.php and it works! That's awesome bro. And thank you very much; you're my life saver:)
For others who might run into the same problem or need to do the same thing, please refer the code above. I didn't do it by creating a module, but adding codes in the template file should work. Just replacing the first line with this:
<?phpfunction YOURTHEME_form_alter(&$form, &$form_state, $form_id){
?>
I have one question. As I need to do the same thing to many specific content types, I just wonder how to refine the codes into something more concise so that only minor change would be needed when adding another content type, say content type test 2, test 3, ...? Now to apply the change to 2 content types, I added four functions into the template.php file. It might be a little long with more content types added this way.
Again, thank you for this.
=-=
There are two methods of dealing with titles in D7 beyond the exclude node title module.
http://drupal.org/project/title = integrates title field with field api which then allows to field to be disabled on manage display tab
http://drupal.org/project/auto_nodetitle = which allows on to use tokens to set the title of a node and hide it from display.
re
Thank you for your suggestion VM. I tried the module but I'm afraid the issue is little out of the scope of the title module. It seems to me that the title module deals with the title of a node, not the title of a node form . Let's say the content type is named "Test". What I was trying to accomplish is to get removed the title "Create Test". If I want to create a "Test" node, say "About Us", that's where the title module might be helpful, espcially if I need some other cck fields to be used as the default title field. But I might need this module in the future so thank you for letting me know about it: )
For others interested in this issue:
Also I'm currently using the auto_nodetitle. This module handles node titles like "About Us" but not node form title "Create Test". It's pretty good though.
exclude node title is a module that allows users to handle both node titles and node form titles. As for me, I use it to hide "Create Test", which is successful, but it won't be able to prevent the title from display if the page reloads due to some required fields left blank. That brought me to the original issue.
=-=
I listed those modules for anyone who locates this thread and is dealing with node titles based on other needs, as this thread is a bit murky after reading the title and the opening post.
as an aside, titles on the node form itself (if not conditional) can be removed from display with a css declaration instead of module logic in template.php. If node form titles are conditional, they could be dealt with with an if/else statement in a tpl.php file. I'd think.