0

Here's the code I'm using to render the comment form, inside node.tpl.php:

$comment = new stdClass;
$comment->nid = $node->nid;
echo render(drupal_get_form('comment_form'), $comment);

But the output HTML is: enter image description here Note the lack of the body field.

To start debugging, I implemented hook_form_alter() and used print_r() on the first $form argument that gets passed to the function. Here's the full output. It also seems to lack any indication of a body field:

Array
(
    [#node] => 
    [#id] => comment-form
    [#attributes] => Array
        (
            [class] => Array
                (
                    [0] => comment-form
                )

        )

    [#theme] => Array
        (
            [0] => comment_form__node_
            [1] => comment_form
        )

    [#action] => /commons/comment/reply/
    [author] => Array
        (
            [#weight] => -2
            [_author] => Array
                (
                    [#type] => item
                    [#title] => Your name
                    [#markup] => Eric Biewener
                )

            [name] => Array
                (
                    [#type] => value
                    [#value] => Eric Biewener
                )

            [mail] => Array
                (
                    [#type] => textfield
                    [#title] => E-mail
                    [#default_value] => 
                    [#required] => 
                    [#maxlength] => 64
                    [#size] => 30
                    [#description] => The content of this field is kept private and will not be shown publicly.
                    [#access] => 
                )

            [homepage] => Array
                (
                    [#type] => textfield
                    [#title] => Homepage
                    [#default_value] => 
                    [#maxlength] => 255
                    [#size] => 30
                    [#access] => 
                )

            [date] => Array
                (
                    [#type] => textfield
                    [#title] => Authored on
                    [#default_value] => 
                    [#maxlength] => 25
                    [#size] => 20
                    [#access] => 
                )

            [status] => Array
                (
                    [#type] => radios
                    [#title] => Status
                    [#default_value] => 1
                    [#options] => Array
                        (
                            [1] => Published
                            [0] => Not published
                        )

                    [#access] => 
                )

        )

    [subject] => Array
        (
            [#type] => textfield
            [#title] => Subject
            [#maxlength] => 64
            [#default_value] => 
            [#access] => 1
            [#weight] => -1
        )

    [is_anonymous] => Array
        (
            [#type] => value
            [#value] => 
        )

    [cid] => Array
        (
            [#type] => value
            [#value] => 
        )

    [pid] => Array
        (
            [#type] => value
            [#value] => 
        )

    [nid] => Array
        (
            [#type] => value
            [#value] => 
        )

    [language] => Array
        (
            [#type] => value
            [#value] => und
        )

    [uid] => Array
        (
            [#type] => value
            [#value] => 0
        )

    [node_type] => Array
        (
            [#type] => value
            [#value] => comment_node_
        )

    [actions] => Array
        (
            [#type] => actions
            [submit] => Array
                (
                    [#type] => submit
                    [#value] => Save
                    [#access] => 1
                    [#weight] => 19
                )

            [preview] => Array
                (
                    [#type] => submit
                    [#value] => Preview
                    [#access] => 1
                    [#weight] => 20
                    [#submit] => Array
                        (
                            [0] => comment_form_build_preview
                        )

                )

        )

    [#parents] => Array
        (
        )

    [#pre_render] => Array
        (
            [0] => _field_extra_fields_pre_render
        )

    [#entity_type] => comment
    [#bundle] => comment_node_
    [#form_id] => comment_form
    [#type] => form
    [#build_id] => form--BpKXguXKLfbkSvL3gtwLoDDtogZ1qdrJDSm-JeiALw
    [form_build_id] => Array
        (
            [#type] => hidden
            [#value] => form--BpKXguXKLfbkSvL3gtwLoDDtogZ1qdrJDSm-JeiALw
            [#id] => form--BpKXguXKLfbkSvL3gtwLoDDtogZ1qdrJDSm-JeiALw
            [#name] => form_build_id
        )

    [#token] => comment_form
    [form_token] => Array
        (
            [#id] => edit-comment-form-form-token
            [#type] => token
            [#default_value] => 7sCRtZn-FudO7YYGoEA0unxc1Mr6d30_yXnfaU-6oJM
        )

    [form_id] => Array
        (
            [#type] => hidden
            [#value] => comment_form
            [#id] => edit-comment-form
        )

    [#method] => post
    [#theme_wrappers] => Array
        (
            [0] => form
        )

    [#tree] => 
    [#validate] => Array
        (
            [0] => comment_form_validate
        )

    [#submit] => Array
        (
            [0] => comment_form_submit
        )

)

I'm not sure what debugging steps to take next. Seems like maybe some other implementation of hook_form_alter() is removing that field, but I don't know how to look for that.

1 Answer 1

1

You're passing the $comment variable as an argument to render() instead of drupal_get_form(), so the body field won't be attached.

Your last line just needs to change to:

echo render(drupal_get_form('comment_form', $comment));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.