Hi all, I’ve created a dashboard widget so that i can see the total number of form submissions on a site, but it’s outputting Zero. I can’t work out what i’ve done wrong - any pointers?
See below:
Snippet code:
<?php
$corePath = $modx->getOption('formit.core_path', null, $modx->getOption('core_path') . 'components/formit/');
$modx->addPackage('formit', $corePath . 'model/');
// Log the path being used to load the model
$modx->log(xPDO::LOG_LEVEL_ERROR, 'FormIt model path: ' . $corePath . 'model/', '', 'countFormItSubmissions');
// Get the total count
$count = $modx->getCount('FormItForm');
// Log the result of the count operation
$modx->log(xPDO::LOG_LEVEL_ERROR, 'FormIt submissions count: ' . $count, '', 'countFormItSubmissions');
return "<div class='formit-submission-count'>Total Form Submissions: <strong>" . $count . "</strong></div>";
If it’s MODX 3, then use the fully qualified class name (which includes the namespace):
// Get the total count
$count = $modx->getCount('Sterc\\FormIt\\Model\\FormItForm');
Also, I don’t think you have to add the package yourself in MODX 3. This should work:
<?php
use Sterc\FormIt\Model\FormItForm;
// Get the total count
$count = $modx->getCount(FormItForm::class);
return "<div class='formit-submission-count'>Total Form Submissions: <strong>" . $count . "</strong></div>";
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.