Posted by Bios450 on March 3, 2009 at 12:23pm
| Project: | Question |
| Version: | 6.x-1.x-dev |
| Component: | User interface |
| Category: | support request |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Issue Summary
Hello
Why when I reply to a question from a blank Title field???
That is right???
Can I do something like that, instead of Title to display Questioner???
Give like to do??? Just for the questions on my site does not need a theme issue
Thanks
Comments
#1
If I understand the question correctly. The original post is asking why there is a blank Title field on question nodes when a question is selected to be answered.
The reason, of course, is that nodes require a title. So this makes sense. It does seem though, like it could be pre-populated with a portion of the question field.
Unfortunately, since this module stores its data in a separate table, doesn't implement any CCK fields, or tokens, this can't be accomplished without writing a bit of code.
On the plus side, that bit of code is pretty simple.
So, for example, if you wanted to put user's question as the title, it could be done like so...
Create a custom_functions module. There's lots of info for doing so in the drupal handbook & api docs. The relevant code in the module would be this:
<?php
function custom_functions_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'question_node_form') {
// If there is no value set for the title, set it to "[questioner_name]'s Question", otherwise preserve existing value.
$form['title']['#default_value'] = (!$form['title']['#default_value']) ? $form['questioner']['#default_value'] ."'s Question" : $form['title']['#default_value'];
// Change title field to type hidden so it won't appear on form:
$form['title']['#type'] = 'hidden';
// Optionally, if we now want to hide the questioner field:
$form['questioner']['#type'] = 'hidden';
}
}
#2
The attached image represents what you would end up with from my code sample above. Notice, neither the title or questioner fields are visible.
The end result is that if a question I posted were answered it would be titled tcindie's Question with the rest of the behavior intact as the module provides.
If the title then is truly not necessary on your site, you would just update (or create and configure) your node-question.tpl.php file, so it does not display the title. ;)