Using isset or is not set PHP variable with extra fields?

by Azur   Last Updated July 30, 2020 09:10 AM - source

I have an issue with setting up variables - if custom field is filled then is should be shown, if it's empty - then date (+1 month from todays date) is shown. But it doesn't work properly, custom field values are shown as they should. But I can't get the date if field value is empty. Please, help!


    if (isset($fields['exp-date'])) {
        echo $field_value = $fields['exp-date']->rawvalue;
        $timeset = $fields['exp-date']; // then assign
    if (!isset($fields['exp-date'])) {
        echo (new DateTime('+1 month'))->format('d.m.Y');
        $timeset = '';

P.S. I get custom fields shown in module using the next code and FieldsHelper (everything works perfectly).

<?php $item->jcfields = FieldsHelper::getFields('com_content.article', $item, true);
        $fields = [];
        foreach($item->jcfields as $jcfield)
            $fields[$jcfield->name] = $jcfield;

Related Questions

Params in Custom Component List View

Updated August 08, 2017 00:10 AM

Default value for repeatable custom field

Updated July 23, 2019 17:10 PM