I am somewhat experienced with PHP but not so much with Joomla's design. I have an event management component (iCagenda). It has a page to edit events. There is the ability to add custom fields. But it doesn't allow a date type field. So I am trying to copy how the component uses an existing date field (startdate).

In the file that handles the event input, there is this, for instance:

<?php echo $this->form->getInput('startdate'); ?>

At the very top of the page there is this

defined('_JEXEC') or die();
$app = JFactory::getApplication();
$document = JFactory::getDocument();

then later, this

JHtml::_('formbehavior.chosen', 'select');

This page does not have a top level function or anything, it just goes right into if-else statements. Not being familiar with object-oriented terminology, I have no idea if this is considered an object or what.

This page calls a function to display custom fields:

echo icagendaCustomfields::loader(2);

Then in the file that handles the display of custom fields, there is this at the top

defined('_JEXEC') or die();
class icagendaCustomfields

In the loader function there is this

static public function loader($parent_form)
    $app = JFactory::getApplication();
    $session = JFactory::getSession();

And eventually a call to icagendaCustomfields::displayField

In displayField, there is this call

$app = JFactory::getApplication();

Then the function creates the form html, which is where I am trying to change the code to make one of he custom text fields a date field. Here is the relevant code:

$cf_fields.= '<div class="' . $ic_prefix . 'controls' . $is_list . '">';

    // Field Type TEXT
    if ($type == 'text')

        // enable a date field here (for instance for the registation due date custom field)
        if ($slug === "registration_due_date"){

        // First - try and test that I can get the already existing event startdate field to display

        $cf_fields.= $this->form->getInput('startdate');
        } else {

        $cf_fields.= '<input type="'.$type.'"';
        $cf_fields.= ' id="' . $slug . '_slug"';
        $cf_fields.= ' name="' . $ic_data . '['.$slug.']"';
        $cf_fields.= ' value="'.$value.'"';
        $cf_fields.= ' placeholder="'.$options.'"';
        if ($app->isAdmin()) $cf_fields.= $text_required;
//      if ($app->isSite()) $cf_fields.= $text_required;
        $cf_fields.= ' />';

This fails above at this line: $cf_fields.= $this->form->getInput('startdate');

The error is "Using $this when not in object context"

Now, this startdate form is an already existing field in the event edit section, so I am just adding this line to confirm I can get things working before going on. Ultimately I need the registration_due_date field to act like the startdate field (i.e. a calendar date select box).

Any ideas? Sorry for such a long post. I am just trying to understand where in the flow to best make changes.

1 Answer 1


$this can only be called inside an instantiated PHP class, an object.

If you are calling an static method from PHP class, then there is no object context. Thus, $this will fail.

To call "loader" method, you have to write:

$agenda = new icagendaCustomfields; // Add params if they are required

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.