Сделал создание и редактирование ресурсов по инструкции — Текст ссылки...

Код сниппета formit2resource

<?php
$doc = $modx->getObject('modResource',array('id'=>$hook->getValue('resource_id')));
 
if (empty($doc)){
    $doc = $modx->newObject('modResource');
    $doc->set('createdby', $modx->user->get('id'));
}
else{
    $doc->set('editedby', $modx->user->get('id'));
}
 
$allFormFields = $hook->getValues();
foreach ($allFormFields as $field=>$value)
{
 
   if ($field !== 'spam' && $field !== 'resource_id'){
         $doc->set($field, $value);
    }
}
$alias = $doc->cleanAlias($fields['pagetitle']);
if($modx->getCount(modResource, array('alias'=>$alias))!= 0) {
$count = 1;
$newAlias = $alias;
while($modx->getCount(modResource, array('alias'=>$newAlias))!= 0) {
$newAlias = $alias;
$newAlias .= '-' . $count;
$count++;
}
$alias = $newAlias;
}
$doc->set('alias',$alias);
$doc->set('template', $template);
$doc->save();
 
foreach ($allFormFields as $field=>$value)
{
    if (!empty($value) && $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();
    }
}
$modx->cacheManager->refresh();
 
return true;


Код сниппета formit2file

<?php
// initialize output;
$output = true;
$counter = 1;
 
// valid extensions
$ext_array = array('jpg', 'png', 'gif', 'JPG', 'mp3');
$mydir = $modx->user->get('id'); // Path from root that user specifies
 
// create unique path for this form submission
$uploadpath = 'assets/uploads/'.$mydir.'/';
 
// get full path to unique folder
$target_path = $modx->config['base_path'] . $uploadpath;
 
// get uploaded file names:
$submittedfiles = array_keys($_FILES);
 
// loop through files
foreach ($submittedfiles as $sf) {
 
    // Get Filename and make sure its good.
    $filename = basename( $_FILES[$sf]['name'] );
 
    // Get file's extension
    $ext = pathinfo($filename, PATHINFO_EXTENSION);
    $ext = mb_strtolower($ext); // case insensitive
 
    // is the file name empty (no file uploaded)
    if($filename != '') {
         
        // is this the right type of file?
        if(in_array($ext, $ext_array)) {
     
            // clean up file name and make unique
            $filename = $counter . '.' . $ext; 
            $filename = str_replace(' ', '_', $filename); // spaces to underscores
            $filename = date("Y-m-d_G-i-s_") . $filename; // add date & time
             
            // full path to new file
            $myTarget = $target_path . $filename;
             
            // create directory to move file into if it doesn't exist
            mkdir($target_path, 0755, true);
             
            // is the file moved to the proper folder successfully?
            if(move_uploaded_file($_FILES[$sf]['tmp_name'], $myTarget)) {
                // set a new placeholder with the new full path (if you need it in subsequent hooks)
                $myFile = $uploadpath . $filename;
                $hook->setValue($sf,$myFile);
                // set the permissions on the file
                if (!chmod($myTarget, 0644)) { /*some debug function*/ }
                 
            } else {
                // File not uploaded
                $errorMsg = 'There was a problem uploading the file.';
                $hook->addError($sf, $errorMsg);
                $output = false; // generate submission error
            }
         
        } else {
            // File type not allowed
            $errorMsg = 'Type of file not allowed.';
            $hook->addError($sf, $errorMsg);
            $output = false; // generate submission error
        }
     
    // if no file, don't error, but return blank
    } else {
        $hook->setValue($sf, '');
    }
$counter = $counter + 1;
}
return $output;


Код формы

[[+fi.error.error_message]]
<form class="cartform" action="[[~[[*id]]]]" enctype="multipart/form-data" method="post"><input type="hidden" name="nospam:blank" />
<input type="hidden" name="resource_id" value="[[+fi.id]]" />
<input id="parent" type="text" name="parent" value="ID контейнера на модерацию" />
<div class="label">Название</div>
[[+fi.error.pagetitle]]
<input class="field" type="text" name="pagetitle" value="[[+fi.pagetitle]]" />
<div class="star">*</div>
<div class="label">Город</div>
[[+fi.error.city]]
<input class="field" type="text" name="city" value="[[+fi.city]]" />
<div class="star">*</div>
<center>
<h3>Подробное описание</h3>
[[+fi.error.content]]
<textarea class="textinput" cols="70" name="content" rows="10">[[+fi.content]]</textarea>
</center>
<h3>Прикрепить фотографии:</h3>
Вы можете разместить в каталоге до пяти фотографий. Допустимые форматы: .jpg, .png, .gif
<table class="addform">
<tbody>
<tr>
<td class="label">Основное фото или логотип<span class="impot">*</span></td>
<td class="input"><span class="error">[[+fi.error.img]]</span><input id="file" type="file" maxlength="100000" name="img" value="[[+fi.img]]" /></td>
</tr>
<tr>
<td class="label">Дополнительное фото (1)</td>
<td class="input"><span class="error">[[+fi.error.foto1]]</span><input id="foto1" type="file" maxlength="100000" name="foto1" value="[[+fi.foto1]]" /></td>
</tr>
<tr>
<td class="label">Дополнительное фото (2)</td>
<td class="input"><span class="error">[[+fi.error.foto2]]</span><input id="foto2" type="file" maxlength="100000" name="foto2" value="[[+fi.foto2]]" /></td>
</tr>
<tr>
<td class="label">Дополнительное фото (3)</td>
<td class="input"><span class="error">[[+fi.error.foto3]]</span><input id="foto3" type="file" maxlength="100000" name="foto3" value="[[+fi.foto3]]" /></td>
</tr>
<tr>
<td class="label">Дополнительное фото (4)</td>
<td class="input"><span class="error">[[+fi.error.foto4]]</span><input id="foto4" type="file" maxlength="100000" name="foto4" value="[[+fi.foto4]]" /></td>
</tr>
</tbody>
</table>
<input class="add-button" type="submit" value="Отправить на модерацию" />
</form>


Все прекрасно работает.
Вопрос!

Как сделать, что бы созданные ресурсы через данную форму публиковались автоматическ?