Page 1 of 1

[SOLVED] Modifying com_content JForm

Posted: Wed Jan 19, 2011 3:57 am
by chamberlain2007
Hi there. I am looking for a way to add a parameter to the article form. One way I saw on the Internet to do it is by adding a listener onContentPrepareForm($form, $data), and then edit the $form object. My code for this method is as follows:

public function onContentPrepareForm($form, $data) {
if($form->getName() == 'com_content.article') {
$form->loadFile('article_comment', false);

My XML file (article_comment.xml) is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<fields name="commentsOptions">
<fieldset name="comments" label="Comments">
description="Enable comments"
label="Enable comments"
message="Enable comments">
<option value="1">Yes</option>
<option value="0">No</option>

The hook seems to work, and the print_r($form) statement prints the data INCLUDING my field, however the form itself is unaffected. Is there a method available to apply the changes to $form? Or am I doing this completely wrong?

I realize it is possible to hack the main form, but I'd like to avoid that if possible.


Re: Modifying com_content JForm

Posted: Wed Jan 19, 2011 4:46 pm
by chamberlain2007
Ok I solved my own problem! Basically, the problem was the the name of <fields> had to be "attribs", and now it's all working!