Dev:Adding a Comment Form

From Habari Project

Jump to: navigation, search

Habari can create a comment form for you, and beginning with version 0.7 this will be the only comment form input Habari will accept. This uses FormUI.

The form is inserted with the following:

<?php $post->comment_form()->out(); ?>

You can modify the form using the action_form_comment hook in your theme.php.

For example, the following changes the label text:

public function action_form_comment( $form ) {
	$form->cf_commenter->caption = '<strong>Name</strong>';
	$form->cf_email->caption = '<strong>Mail</strong> (will not be published)';
	$form->cf_url->caption = '<strong>Website</strong>';
	$form->cf_content->caption = '<strong>Comment</strong>';

Since this is built with FormUI you can add and move controls. This moves some of them into a fieldset:

public function action_form_comment( $form ) { 
	$form->append( 'fieldset','cf_commenterinfo', 'your contact information' ); 
	$form->move_before( $form->cf_commenterinfo, $form->cf_commenter );
	$form->cf_commenter->move_into( $form->cf_commenterinfo );
	$form->cf_commenter->caption = 'name';
	$form->cf_commenter->size = 22;
	$form->cf_email->move_into( $form->cf_commenterinfo );
	$form->cf_email->caption = 'email';
	$form->cf_email->size = 22;
	$form->cf_url->move_into( $form->cf_commenterinfo );
	$form->cf_url->caption = '<acronym title="Uniform Resource Identifier">URI</acronym>';
	$form->cf_url->size = 22;

If you would like to change the styling/markup of the existing formcontrol templates more than can be achieved with CSS and the above, you may want to replace the specific templates used to construct the form.

They are:

  • formcontrol_form, containing the code in the 'header' of the form. It is highly unlikely you would replace/modify this.
  • formcontrol_text, used for Name, Email and URL.
  • formcontrol_textarea, used for the Comment content.
  • formcontrol_submit, used for the Submit button.

Here is an example of a function replacing every single possible template:

public function action_form_comment( $form ) 
	$this->add_template( 'formcontrol_form', dirname(__FILE__).'/forms/formcontrol_form.php', true );
	$this->add_template( 'formcontrol_text', dirname(__FILE__).'/forms/formcontrol_text.php', true );
	$this->add_template( 'formcontrol_textarea', dirname(__FILE__).'/forms/formcontrol_textarea.php', true );
	$this->add_template( 'formcontrol_submit', dirname(__FILE__).'/forms/formcontrol_submit.php', true );

Called as above, the modified templates in the theme's /forms directory will replace the existing ones, without needing to explicitly specify the new templates.

Alternatively, you could outsource comments on your site to a comment service, such as Disqus.

Personal tools