[SOLVED] Modifying com_content JForm

This forum is for general questions about extensions for Joomla! 2.5.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
chamberlain2007
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Jan 19, 2011 3:51 am

[SOLVED] Modifying com_content JForm

Post by chamberlain2007 » Wed Jan 19, 2011 3:57 am

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') {
JForm::addFormPath(dirname(__FILE__).'/articles');
$form->loadFile('article_comment', false);
print_r($form);
}
}

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

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

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.

Thanks!
Last edited by chamberlain2007 on Wed Jan 19, 2011 4:46 pm, edited 1 time in total.

chamberlain2007
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Jan 19, 2011 3:51 am

Re: Modifying com_content JForm

Post by chamberlain2007 » Wed Jan 19, 2011 4:46 pm

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!


Locked

Return to “Extensions for Joomla! 2.5”