E_NOTICE: Trying to access array offset on value of type null?

8 posts by 2 authors in: Forums > CMS Builder
Last Post: September 21   (RSS)

By gkornbluth - September 20 - edited: September 20

Good morning All,

I'm running CMSB version 3.56 with PHP 7.4 and I'm getting the following error every time I access the record list for  sections called  e_blast_general or the section called e_blast_press_release:

E_NOTICE: Trying to access array offset on value of type null
/home3/mrqsygmy/public_html/cmsAdmin/lib/menus/default/list.php (line 129)
https://dbtproviders.com/cmsAdmin/admin.php?menu=e_blast_general

and an identical error for lines 115 and 131.

I got the same errors in Version 3.55 and thought the upgrade would solve the issue.

I thought of just putting an @ in front of the offending code, IE: <?php if (@$searchField['requiresLabel']): ?>, <?php echo @$searchField['html'] ?> and <?php if (@$searchField['description']): ?> but wanted to check with you guys first in case that would just mask a bigger issue.

I've attached a screen shot of one of the error log entries, the e_blast_general.ini.php file, and the e_blast_press_release.ini.php file.

Any Thoughts?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - September 21

Hey Daniel,

Glad I asked. 

I'll give it a  try.

Any idea why this is happening in the first place?

Thanks

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - September 21 - edited: September 21

Thanks Daniel,

No errors now...

Just curious if I did the right thing, Daniel.

One of the offending lines was:

<?php echo $searchField['html'] ?>

So I surrounded it with an if to check if the value was empty,

<?php if (!empty($searchField['html'])): // added 9/12/22 ?>
<?php echo $searchField['html'] ?>
<?php endif ?>

I'm still interested to find out why I got these errors in the first place.

At any rate, here's what I did in case someone else come up with the same kind of issue. (starts at line 113 in version 3.56 in cmsAdmin/lib/menus/default/list.php)

<!-- simple search -->
<?php $searchField = getSearchField($primarySearchRow, 'PRIMARY'); ?>
<?php // if ($searchField['requiresLabel']): ?>
<?php if (!empty($searchField['requiresLabel'])): // added 9/12/22 per Daniel ?>
<div class="row" style="margin-bottom: 5px;">
<div class="col-md-2">
<label class="control-label">
<?php echo $searchField['label'] ?>
</label>
</div>
<div class="col-md-10">
<?php echo $searchField['html'] ?>
</div>
</div>
<?php else: ?>
<div class="row" style="margin-bottom: 5px;">
<div class="col-md-12">
<?php if (!empty($searchField['html'])): // added 9/12/22 ?>
<?php echo $searchField['html'] ?>
<?php endif ?>
</div>
<?php // if ($searchField['description']): ?>
<?php if (!empty($searchField['ddescription'])): // added 9/12/22 per Daniel ?>
<div class="help-block col-md-12">
<?php echo $searchField['description']; ?>
</div>
<?php endif; ?>
</div>
<?php endif ?>

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - September 21

Hey Jerry,

Apologies, I didn't realize at first this was happening on a CMSB admin page!

It looks like this error shows up if a section isn't configured with any search fields in the section editor (under the "Sorting" tab when editing a section). If you add any search field (or just "_all_"  to restore the default search bar) it should get rid of the errors.

From what I can see, your changes are probably sufficient, but here's a more "official" patch that should fix the errors in that section:

      <!-- simple search -->
      <?php $searchField = getSearchField($primarySearchRow, 'PRIMARY'); ?>
      <?php if (!empty($searchField)): ?>
        <?php if ($searchField['requiresLabel']): ?>
          <div class="row" style="margin-bottom: 5px;">
            <div class="col-md-2">
              <label class="control-label">
                <?php echo $searchField['label'] ?>
              </label>
            </div>
            <div class="col-md-10">
              <?php echo $searchField['html'] ?>
            </div>
          </div>
        <?php else: ?>
          <div class="row" style="margin-bottom: 5px;">
            <div class="col-md-12">
              <?php echo $searchField['html'] ?>
            </div>
            <?php if ($searchField['description']): ?>
              <div class="help-block col-md-12">
                <?php echo $searchField['description']; ?>
              </div>
            <?php endif; ?>
          </div>
        <?php endif ?>
      <?php endif; ?>

This would replace lines 114-137 in /cmsb/lib/menus/list.php (the original version, before your changes)

Let me know if you have any other questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 21 - edited: September 21

Thanks Daniel,

Appreciate your effort. I'll apply that solution

Is that going to be implemented going forward?

There's an instruction that comes up in the editor when you go to enter the search criteria that says:

Disabling Search If you don't want any search options displayed just leave the box above blank.

This seems contrary to the code that was there in lists.php

Jerry

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - September 21

Hey Jerry,

Yes - I'll get that patch in the next CMSB release so you don't have to worry about it being overwritten in future updates.

I believe this specific error is new in PHP 7.4, so it likely worked to disable the search fields in this way when it was written. But it's not something we see commonly used, so the conditions for the error are pretty rare.

In any case, thanks for reporting this!

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 21

Glad to help

Have a great rest of the week (and beyond...)

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php