By DrupalNovice on
Hi!
Ok, I've been trying to figure this out a while know, so I thoguht I'd do post here.
What I'm trying to do is:
a) change the data (array) that's building the comment_form form
b) place THAT form on a specific place on a specific node type page
So, b) I've already figured out...
function phptemplate_preprocess_node(&$vars) {
$vars['comments'] = $vars['comment_form'] = '';
/* I will change this if-statement to match my specific node type */
if (module_exists('comment') && isset($vars['node'])) {
$vars['comments'] = comment_render($vars['node']);
$vars['comment_form'] = drupal_get_form('comment_form', array('nid' => $vars['node']->nid));
}
/** Now I can place the $comment_form variable in my template file wherever I want... **/
...but I can't seem to wrap my thought's about a).
SO THE QUESTION IS:
########################################################
How do I alter a form (the comment_form form) before I pass it to the template file ?
(meaning that the form I override doesn't affect the same form on any other pages than
what the template file targets)
########################################################
Help
Comments
Use hook_form_alter()
You would want to write a module that implements hook_form_alter(). You can use form_id to determine it is comment form and will need to look at $form to see what you can use to check for node type.
Thanks nevets for your answer
Thanks for the answer. I'm aware of the hook_form _alter() function.
I'm wondering: is there any way to do this in the theme layer? I realize that Adding elements must be done in a dedicated module, but I'm just going to Remove some elements from the array.. and I'm just going to use this feature in the selected theme, so building a module for this task is a bit overkill..
I'm aware of the [themename]_[form_name] and the hook_theme functions..my question is: Are these the only ways to alter the $form array in the theme layer? And how do I use these functions together with my phptemplate_preprocess_node() function to achieve a form override only for the content type I specified?
Maybe I should nest some functions like this?
?
Nesting is not the answer,
Nesting is not the answer, using [themename]_[form_name]will allow you to render only selected elements from the form. See http://drupal.org/node/112358 for an example. You can use unset() to remove elements you do not want.
You're right
You're right nevets, nesting is not the answer..I tried the following...:
...and no changes was made to the form whatsoever.
I even tried the function on it's own:
...and it didn't work either.
Anyway, you probably meant doing this in the dedicated module..
I don't understand why the Drupal Core developers removed the two arguments from drupal_get_form()..:
4.7
drupal_get_form($form_id, &$form, $callback = NULL)
5 – 7
drupal_get_form($form_id)
...I could have used it to pass in a modified $forms array..(but something else would probably have messed it up so it wouldn't have worked anyway..=P(
So the Only solution to my problem is to build a custom module to achieve the results? (a last nail in the coffin'? plz ;)
Missing call to form_render.
I think if you change mytheme_comment_form() to
you will closer. (I wonder about unsetting #submit and submit)
Thanks nevets
Thanks nevets, I got it working now..
It seemed that the only way to achieve what I want on the theme layer was to use a preprocess_node function and a theme_form function nested inside the preprocessor function. I then assigned the modified form to the referenced $var parameter in the preprocess_node function through drupal_render('form_name'). And last but not least, I printed out the form on the specific location I wanted on the node page.
Almost
With your code I'm able to print comments and comment_form in node(-xxx).tpl.php exactly where I want.
The comments.tpl.php defines the html output. Allright.
But I can not define the output of the comment_form. It is always the same with standard fields. Also the allowed memory is in this constellation not enough for a preview. But unsetting preview would ...
And the (core) pagination links are disapeared. Hm.
There are comment-form.tpl.php, no cache, all modules up to date, ...
In my template.php:
Also this won't let the comment-form-template work:
Any ideas, what I could try? I have spent already hours searching a solution. Thank you very much.
Yup, _phptemplate_callback
Yup, _phptemplate_callback is obsolete to Drupal 6.x.
Instead use the theme or the theme_render_template functions.
Remember that you must always register any custom theme functions before creating them.
So try adding this to you template file (without the php-tags):
I hope this will help you!
Thank you very much, I'll
Thank you very much,
I'll give it a try.
Not better
does not work.
Also I have detected, that the line
above kills the pagination at the homepage etc.;
and the line
let me place the comment_form but without formatting
:-/