Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikhaildegtuarev/6c3f1e3dfb246e22e8bed919bc8cf6e7 to your computer and use it in GitHub Desktop.
Save mikhaildegtuarev/6c3f1e3dfb246e22e8bed919bc8cf6e7 to your computer and use it in GitHub Desktop.
<?php
if ($_POST['a<?php
if ($_POST['action'] != 'grete-task'){
return $form;
}
// Сниппет будет получать данные из формы методом POST
$title = isset($_POST['title']) && $_POST['title']!='' ? $_POST['title'] : 'Новое задание';
$content = $_POST['content'];
$introtext = $_POST['introtext'];
$description = $_POST['description'];
$parent = isset($parent) ? $parent : 1;
$template = isset($template) ? $template : 11;
$publishedon = date('Y-m-d H:i:s');
$phone = isset($_POST['phone']) && $_POST['phone'] !='' ? $_POST['phone']: 'Не указан';
$email = isset($_POST['e-mail']) ? $_POST['e-mail']: '';
$date = isset($_POST['srok']) && $_POST['srok'] !=''? $_POST['srok']: $publishedon;
$name = isset($_POST['name']) && $_POST['name'] !=''? $_POST['name']: 'Не указано';
//print_r($_POST); die;
// Если некоторые значения не будут указаны,
// они будут установлены по умолчанию
if (!$introtext) $introtext = $title;
if (!$description) $description = $introtext;
// Создаем ресурс
$newResource = $modx->newObject('modResource');
// Заполняем нужные значения
$newResource->set('pagetitle',$title);
$newResource->set('longtitle',$title);
$newResource->set('description',$description);
$newResource->set('introtext',$introtext);
$newResource->set('content',$content);
$newResource->set('alias',$title);
$newResource->set('template',$template);//
$newResource->set('published',0);
$newResource->set('parent',$parent);
$newResource->set('publishedon',$publishedon);
$newResource->set('hidemenu',0);
$id = $newResource->get('id');
$newResource->save();
$newResource->set('phone', null);
$newResource->setTVValue('phone', $phone);
$newResource->setTVValue('adres', '');
$newResource->setTVValue('e-mail', $email);
$newResource->setTVValue('price', (int)$_POST['price']);
$newResource->setTVValue('srok', $date);
$newResource->setTVValue('name', $name);
$newResource->setTVValue('sphera', (int)$_POST['sphera']);
// Очищаем кеш, чтобы изменения были видны сразу
$modx->cacheManager->clearCache();
return $done;
/*-- ВЫВОД -- */
[[!addTask? &template=`11` &parent=`11` &form=`
<form method="POST">
<div class="form" >
<div class="column-zakaz-left">
<label>Выберите категорию:</label>
<select name="sphera">
[[getResources?
&sortby=`{"menuindex":"ASC"}`
&tpl=`option`
&limit=`all`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&parents=`24` ]]
</select><br>
<br>
<label>Заголовок задания:</label><input type="text" name="title" required><br>
<label>Опишите ваше задание</label><textarea name="content" required></textarea><br>
<label>Срок исполнения:</label>
<input type="date" name="srok" placeholder="Дата" >
<img src="dist/images/ici-date.png" width="20" height="19" alt=""/><br>
<label>Цена задания:</label>
<ul class="cena-zadaniya">
<li>
<input id="" class="radio" name="OpenPrice" value="0" type="radio">
<span>Я готов заплатить</span><input type="text" name="price" placeholder="Введите сумму">
<img src="dist/images/rub.png" width="20" height="19" alt=""/><br><br>
</li>
<li><input id="" class="radio" name="OpenPrice" value="1" type="radio"><span>Пусть исполнители сами предложат цену</span></li>
</ul>
<div class="kontakt-danue">
<div class="zakaz-title"><h3>Ваши контактные данные:</h3></div>
<input type="text" name="name" placeholder="Ваше имя" required><br>
<input type="text" name="phone" placeholder="Телефон" required><br>
<input type="text" name="e-mail" placeholder="E-mail" required><br>
</div>
</div>
<div class="column-zakaz-right">
[[$banners]]
</div>
</div>
<input name="action" type="hidden" value="grete-task" />
<button type="submit" class="button-btn">СОЗДАТ ЗАДАНИЕ</button>
</form>
` &done=`<p>Ваше задание принято, оно будет опубликовано после модерации. </p>`]]ction'] != 'grete-task'){
return $form;
}
// Сниппет будет получать данные из формы методом POST
$title = isset($_POST['title']) && $_POST['title']!='' ? $_POST['title'] : 'Новое задание';
$content = $_POST['content'];
$introtext = $_POST['introtext'];
$description = $_POST['description'];
$parent = isset($parent) ? $parent : 1;
$template = isset($template) ? $template : 11;
$publishedon = date('Y-m-d H:i:s');
$phone = isset($_POST['phone']) && $_POST['phone'] !='' ? $_POST['phone']: 'Не указан';
$email = isset($_POST['e-mail']) ? $_POST['e-mail']: '';
$date = isset($_POST['srok']) && $_POST['srok'] !=''? $_POST['srok']: $publishedon;
$name = isset($_POST['name']) && $_POST['name'] !=''? $_POST['name']: 'Не указано';
//print_r($_POST); die;
// Если некоторые значения не будут указаны,
// они будут установлены по умолчанию
if (!$introtext) $introtext = $title;
if (!$description) $description = $introtext;
// Создаем ресурс
$newResource = $modx->newObject('modResource');
// Заполняем нужные значения
$newResource->set('pagetitle',$title);
$newResource->set('longtitle',$title);
$newResource->set('description',$description);
$newResource->set('introtext',$introtext);
$newResource->set('content',$content);
$newResource->set('alias',$title);
$newResource->set('template',$template);//
$newResource->set('published',0);
$newResource->set('parent',$parent);
$newResource->set('publishedon',$publishedon);
$newResource->set('hidemenu',0);
$id = $newResource->get('id');
$newResource->save();
$newResource->set('phone', null);
$newResource->setTVValue('phone', $phone);
$newResource->setTVValue('adres', '');
$newResource->setTVValue('e-mail', $email);
$newResource->setTVValue('price', (int)$_POST['price']);
$newResource->setTVValue('srok', $date);
$newResource->setTVValue('name', $name);
$newResource->setTVValue('sphera', (int)$_POST['sphera']);
// Очищаем кеш, чтобы изменения были видны сразу
$modx->cacheManager->clearCache();
return $done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment