Hi all, I need to use the formit2resource (from
http://ttyl.modx.com/thread/?thread=54204.0%3Bwap&i=1&page=1) snippet on a site, but I've been encountering some strange problems as of late.
I made some slight modifications and have a working instance of it on a separate site, using the same version of FormIt and MODX (currently 2.0.1 and 2.1.3 trad, respectively).
Anyway, the error I'm getting on the site it's not working on happens after you've filled all the fields and hit submit; it goes to a new page and says:
Fatal error: Call to a member function getOption() on a non-object in /home/*snip*/core/model/modx/modresource.class.php on line 681
This happens no matter how many fields I have (I tried reducing it to one simple text field and it still did not work), and no matter how I make the FormIt call (I tried using a FormIt call with only the absolute necessary fields for it to work).
Here is the formit2resource snippet I am using on both sites:
<?php
$doc = NULL;
$doc = $modx->newObject('modResource');
$doc->set('parent', $fi2ResParent);
$doc->set('alias', "event-".time());
$doc->set('context_key', "events");
$doc->set('createdby', $modx->user->get('id'));
$allFormFields = $hook->getValues();
foreach ($allFormFields as $field=>$value)
{
if ($field == 'pagetitle' || $field == 'content')
{
$doc->set($field, $value);
}
}
$doc->set('template', '26');
$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;
A few lines of code were added to the top to attempt to debug, but it didn't change anything.
Here's the full FormIt call I am using:
[[!FormIt? &hooks=`spam,file2formit,formit2resource,redirect` &redirectTo=`3665` &validate=`nospam:blank, pagetitle:required, content:required:stripTags, event-date:required, event-addy:stripTags:required, event-country:required, event-time:required, event-fees:stripTags:required, event-artists:stripTags:required` &fi2ResParent=`3691` &path=`*snip*` &extensions=`jpg,JPG,jpeg,JPEG,png,PNG,gif,GIF` &maxsize=`786432`]]
Any help or ideas is greatly appreciated, and I thank you in advance.