Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aidsoul/bitrix-form
Bitrix Forms
https://github.com/aidsoul/bitrix-form
Last synced: 15 days ago
JSON representation
Bitrix Forms
- Host: GitHub
- URL: https://github.com/aidsoul/bitrix-form
- Owner: aidsoul
- License: mit
- Created: 2023-10-02T10:42:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-27T13:18:14.000Z (9 months ago)
- Last Synced: 2024-12-07T03:52:13.121Z (about 1 month ago)
- Language: PHP
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Example class
```php
*/
class Request extends Form
{
/**
* Массив для работы с почтой
*
* @var array
*/
protected array $mail = [
'eventType' => 'REQUEST_FORM',
'mailTemplateId' => 89
];protected array $modalArr = [
'title' => 'Заявка отправлена!',
'message' => 'Мы ответим Вам в ближайшее время'
];/**
* Поля текущей формы
*
* @var array
*/
protected array $formFields = [
'email' => [
'name' => 'E-mail',
'required' => true
],
'phone' => [
'name' => 'Телефон',
'required' => true
]
];/**
* Валидация поля "Телефон"
*
* @param string $phone
*
* @var void
*/
protected function phone(string $phone): void
{
if (!Validator::phone()->length(12, 12)->validate($phone)) {
$this->setError('phone', 'Неверный формат поля "Телефон"!');
} else {
$this->cleanFields['PHONE'] = $phone;
}
}/**
* Валидация поля "Имя"
*
* @param string $name
*
* @return void
*/
protected function name(string $name): void
{
if (!Validator::length(2, 45)->validate($name)) {
$this->setError('name', 'Строка поля "Имя", должна содержать от 2 до 45 символов');
}
$this->cleanFields['NAME'] = $name;
}/**
* Возвращает массив, который доступен в шаблоне
* $arResult['DATA']
*
* @return array
*/
public function formDataAction(): array
{
$table = getClassByCodeApi($this->formData['API_CODE'] ?? 'RequestForm');
return $table::query()
->setSelect([
'ID',
'NAME',
'CODE',
'SUBTITLE_' => 'SUBTITLE',
'IMAGE_' => 'IMAGE',
])
->setOrder(['SORT' => 'ASC'])
->setFilter(['=CODE' => $this->formData['ELEMENT_CODE']])
->setCacheTtl(53456)->fetch();
}
}
```
##