Formit2Resource

It seems this is not compatible with php 8.x

I have a site where this is used in a primary function of the site. We recently upgrade modx to 3.0x and attempted to update php as well. But we found this broke Formit2Resource.

I’ve attempted to contact the original author from his Github page, but the email address there is no valid and his social media account require premium services to use or says that messages aren’t allowed.

I see that he has also authored another extra called FormitPublisher. It’s not clear to me if this is a replacement for Formit2Resource and again I’m unable to ask him.

Might there be someone with some PHP skills that might be able to determine what needs to be done to make this 8.x compatible? Or if someone knows how to reach the original author?

Thank you!

This is the error message:

Snippet 10 is Formit2Resource.

[12-Jun-2024 14:29:30 UTC] PHP Fatal error:  Uncaught ArgumentCountError: mktime() expects at least 1 argument, 0 given in /home/xxxxxxx/public_html/jobs/core/cache/includes/elements/modx/revolution/modsnippet/10.include.cache.php:12
Stack trace:
#0 /home/xxxxxxx/public_html/jobs/core/cache/includes/elements/modx/revolution/modsnippet/10.include.cache.php(12): mktime()
#1 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modScript.php(88): include('/home/xxxxxxx...')
#2 /home/xxxxxxx/public_html/jobs/core/components/formit/src/FormIt/Hook.php(149): MODX\Revolution\modScript->process()
#3 /home/xxxxxxx/public_html/jobs/core/components/formit/src/FormIt/Hook.php(107): Sterc\FormIt\Hook->load()
#4 /home/xxxxxxx/public_html/jobs/core/components/formit/src/FormIt/Request.php(402): Sterc\FormIt\Hook->loadMultiple()
#5 /home/xxxxxxx/public_html/jobs/core/components/formit/src/FormIt/Request.php(345): Sterc\FormIt\Request->runPostHooks()
#6 /home/xxxxxxx/public_html/jobs/core/components/formit/src/FormIt/Request.php(254): Sterc\FormIt\Request->postProcess()
#7 /home/xxxxxxx/public_html/jobs/core/cache/includes/elements/modx/revolution/modsnippet/1.include.cache.php(21): Sterc\FormIt\Request->handle()
#8 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modScript.php(88): include('/home/xxxxxxx...')
#9 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modParser.php(508): MODX\Revolution\modScript->process()
#10 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modParser.php(221): MODX\Revolution\modParser->processTag()
#11 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modResource.php(521): MODX\Revolution\modParser->processElementTags()
#12 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modResource.php(469): MODX\Revolution\modResource->parseContent()
#13 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modResponse.php(72): MODX\Revolution\modResource->prepare()
#14 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modRequest.php(154): MODX\Revolution\modResponse->outputContent()
#15 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modRequest.php(138): MODX\Revolution\modRequest->prepareResponse()
#16 /home/xxxxxxx/public_html/jobs/core/src/Revolution/modX.php(1499): MODX\Revolution\modRequest->handleRequest()
#17 /home/xxxxxxx/public_html/jobs/index.php(63): MODX\Revolution\modX->handleRequest()
#18 {main}
  thrown in /home/xxxxxxx/public_html/jobs/core/cache/includes/elements/modx/revolution/modsnippet/10.include.cache.php on line 12

Here is the snippet code:

<?php
$doc = $modx->newObject('modResource');
$doc->set('createdby', $modx->user->get('id'));
 
$allFormFields = $hook->getValues(); 
foreach ($allFormFields as $field=>$value)
{
   $doc->set($field, $value);
}

$doc->set('parent', $parent);
$doc->set('alias', mktime()); 
$doc->set('template', '2'); 
$doc->set('published', '0');
$doc->set('unpub_date', $unpub_date);
$doc->set('pagetitle', $pagetitle);
$doc->save();
 
foreach ($allFormFields as $field=>$value)
{
    if ($tv = $modx->getObject('modTemplateVar', array ('name'=>$field)))
    {
        /* handles checkboxes & multiple selects elements */
        if (is_array($value)) {
            $featureInsert = array();
            while (list($featureValue, $featureItem) = each($value)) {
                $featureInsert[count($featureInsert)] = $featureItem;
                }
            $value = implode('||',$featureInsert);
            }   
            
        $tv->setValue($doc->get('id'), $value);

        $tv->save();
    }
}
 
return true;

The problem is the mktime function. With PHP 8, the “hour” parameter is no longer optional. Use time() instead:

...
$doc->set('alias', time());

Excellent! I will give this a try. I"m glad it’s something simple.

I have to coordinate with my client so I may not report back till next week sometime.

Thank you–as always!

This solved the problem.

Thank you so much!

1 Like