Created
December 17, 2021 08:58
-
-
Save 0test/4581e852b0cd1e2c6080f482f99b3033 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('MODX_API_MODE', true); | |
include_once("index.php"); | |
$modx->db->connect(); | |
if (empty ($modx->config)){ | |
$modx->getSettings(); | |
} | |
switch($_REQUEST['q']){ | |
case 'award_form': | |
$result = $modx->runSnippet('FormLister', array( | |
'formid' => 'award_form', | |
'api' => 2, | |
'rules' => [ | |
"name" => [ | |
"required" => "Введите имя" | |
], | |
"comment" => [ | |
"required" => "Текст не может быть пустым", | |
"minLength" => [ | |
"params" => 10, | |
"message" => "Не менее 10 символов" | |
] | |
], | |
"products" => [ | |
"required" => "Нужно выбрать 2 услуги", | |
"minCount" => [ | |
"params" => 2, | |
"message" => "Минимум 2 услуги" | |
] | |
], | |
"department" => [ | |
"required" => "Выберите офис" | |
], | |
"topic" => [ | |
"required" => "Выберите тему" | |
], | |
"agree" => [ | |
"required" => "Вы не можете отправить обращение, если не согласны с правилами" | |
] | |
], | |
'fileRules' => [ | |
"files" => [ | |
"required" => "Приложите от 2 до 5 фото", | |
"maxSize" => [ | |
"params" => 2048, | |
"message" => "Фото не более 2 Мб" | |
], | |
"allowed" => [ | |
"params" => [ ["jpg","jpeg","png"] ], | |
"message" => "Только фото" | |
], | |
"maxCount" => [ | |
"params" => 5, | |
"message" => "Не больше 5 фото" | |
], | |
"minCount" => [ | |
"params" => 2, | |
"message" => "Не меньше 2 фото" | |
] | |
] | |
], | |
'attachments' => 'files', | |
'formControls' => 'agree,topic,department,products', | |
'formTpl' => 'award_form', | |
'noemail'=> '1', | |
'subject' => 'Заявка с сайта', | |
'protectSubmit' => 0, | |
'submitLimit' => 0, | |
'successTpl' => 'successTplFormlisterJson', | |
'prepareAfterProcess' => array(function($modx, $data, $FormLister, $name){ | |
$files = $FormLister->getFormData('files'); | |
if (isset($files['ufile']) && $files['ufile']['error'] === 0) { | |
$dir = 'assets/images/1/'; | |
$filename = $FormLister->fs->takeFileName($files['ufile']['name']); | |
$ext = $FormLister->fs->takeFileExt($files['ufile']['name']); | |
$filename = $modx->stripAlias($filename).'.'.$ext; | |
$filename = $FormLister->fs->getInexistantFilename($dir.$filename,true); | |
if ($FormLister->fs->makeDir($dir) && move_uploaded_file($files['ufile']['tmp_name'],$filename)) { | |
return $data; | |
} | |
} | |
}), | |
)); | |
echo $modx->parseDocumentSource($result); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment