Add form field to com_content in Joomla2.5

166 views
Skip to first unread message

Hassan Z

unread,
Jan 21, 2014, 3:05:29 PM1/21/14
to joomla-de...@googlegroups.com

Can someone help me figure out why this isn't working. It's actually group="content" plugin. I followed examples that I barely found on internet, but it was not enough. Following code was claimed to work but it does not for me.

Here is my onContentPrepareForm

function onContentPrepareForm($form, $data) { echo "working aroptimizer ";

if (!($form instanceof JForm)) {
    $this->_subject->setError('JERROR_NOT_A_FORM');
    return false;
}

// Check we are manipulating a valid form.
if (!in_array($form->getName(), array('com_contact.article'))) {
    return true;
}
// Add the fields to the form.
JForm::addFormPath(dirname(__FILE__) . '/inc');
$form->loadFile('arform', false);

return TRUE;
}

and in inc/arform.xml I have following:

<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="aroptimizer">
<fieldset name="ar"
label="AR Optimizer">
<field name="ar" type="list" label="Audience Match" description="Select your audience">
<option value="1">JSELECT</option>
<option value="1">DEPT_SALES</option>
<option value="2">DEPT_SUPPORT</option>
<option value="3">DEPT_BILLING</option>
<option value="4">DEPT_OTHER</option>
</field>
</fieldset>
</fields>
</form> 

Goal for the above code is just to display form fields. All I wanna do is show some form fields to com_content(?option=com_content) page.

Thank You.

Adam Rifat

unread,
Jan 22, 2014, 8:33:21 AM1/22/14
to joomla-de...@googlegroups.com
Unless you are using a field group that is already present you may also have to modify the template to display the extra fields.

In your case it may look something like:

<?php echo $this->form->getControlGroup('aroptimizer'); ?>
<?php foreach ($this->form->getGroup('aroptimizer') as $field) : ?>
<?php echo $field->getControlGroup(); ?>
<?php endforeach; ?>

If you use something like:
 
<fields name="attribs">
    <fieldset name="basic" label="">
      <field />
  </fieldset>
</fields>

then it should those fields will be added to one of the article tabs. It works for me!

Of course, you will have to save the data back somewhere on a different plugin event as well.

Hassan Z

unread,
Jan 22, 2014, 10:46:51 AM1/22/14
to joomla-de...@googlegroups.com
Hello Adam,
  thanks for your reply. Few things were unclear to me, as I am pretty new to Joomla development. When you say template edit, is it something I can do within my plugin or how do I  achieve that.

Secondly, I did modify my arform.xml to following:
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="attribs">
<fieldset name="basic"
label="AR Optimizer">
<field name="ar" type="list" label="Audience Match" description="Select your audience">
<option value="1">JSELECT</option>
<option value="1">DEPT_SALES</option>
<option value="2">DEPT_SUPPORT</option>
<option value="3">DEPT_BILLING</option>
<option value="4">DEPT_OTHER</option>
</field>
</fieldset>
</fields>
</form>

and yet it does not show up.

lastly, what do you mean by "Of course, you will have to save the data back somewhere on a different plugin event as well."

Thanks


--
You received this message because you are subscribed to a topic in the Google Groups "Joomla! General Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/joomla-dev-general/UP8X-slm98E/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.

Hassan Z

unread,
Jan 22, 2014, 1:11:17 PM1/22/14
to joomla-de...@googlegroups.com

Update: I got the form to show up but the problem is another field is showing up in my custom fieldset. How do I kick it out ? See Screenshot

Adam Rifat

unread,
Jan 23, 2014, 7:56:20 AM1/23/14
to joomla-de...@googlegroups.com
Glad you got it working.

Not sure why the extra field is there. Perhaps you have modified another form or the XML in your added field is not 100% correct?

I am using this on Joomla 3 so maybe there is a bug or problem with your version, I am not sure.

Anyway, if you are using the attribs field then when you save the value should be saved back to the article automatically.

Hassan Z

unread,
Jan 23, 2014, 9:16:39 AM1/23/14
to joomla-de...@googlegroups.com

Yes it does. My next question is how do I show options in there dynamically? I means I'll be making calls to 3rd party api and get objects to display as drop down.

--

Adam Rifat

unread,
Jan 23, 2014, 9:50:43 AM1/23/14
to joomla-de...@googlegroups.com
You would need to either define a custom field type or use the sql field type.

It depends on where and how you list of '3rd party api' is stored?
To unsubscribe from this group and all of its topics, send an email to joomla-dev-general+unsub...@googlegroups.com.

Hassan Z

unread,
Jan 23, 2014, 9:54:28 AM1/23/14
to joomla-de...@googlegroups.com
How can I create custom field types using a group="content" plugin ?
I did not get your question. I simply make a call to API and recieve JSON object, that needs to be shown as dropdown list.


To unsubscribe from this group and all of its topics, send an email to joomla-dev-gene...@googlegroups.com.

Kevin Campbell

unread,
Jan 23, 2014, 10:03:58 AM1/23/14
to joomla-de...@googlegroups.com
Custom field type creation documentation is here: http://docs.joomla.org/Creating_a_custom_form_field_type

Hassan Z

unread,
Jan 23, 2014, 10:07:13 AM1/23/14
to joomla-de...@googlegroups.com
yes, but are those functions gonna work with group="content" plugin ?
getLabel and getInput ?


On Thu, Jan 23, 2014 at 10:03 AM, Kevin Campbell <ke...@tcmsvc.com> wrote:
Custom field type creation documentation is here: http://docs.joomla.org/Creating_a_custom_form_field_type

--

Kevin Campbell

unread,
Jan 24, 2014, 12:15:25 PM1/24/14
to joomla-de...@googlegroups.com
Based on the history of this conversation and you creating the custom type to be used in your xml.  Yes.
Reply all
Reply to author
Forward
0 new messages