PHP code example of msvdev / bitrix-extension-forms
1. Go to this page and download the library: Download msvdev/bitrix-extension-forms library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
msvdev / bitrix-extension-forms example snippets
namespace Components\User\Login;
use Modules\User\Entities\Login;
use Modules\User\Forms\LoginType;
use Msvdev\Bitrix\Forms\Form;
class Component extends \Msvdev\Bitrix\Component\Component
{
public function executeComponent()
{
global $APPLICATION;
global $USER;
$entity = new Login($USER);
$symfonyForm = new Form($this);
$form = $symfonyForm->getFormBuilder()->create(LoginType::class, $entity);
$form->handleRequest();
if ($this->request->isAjaxRequest() && $form->isSubmitted()) {
$APPLICATION->RestartBuffer();
$result = [
'result' => false,
'errors' => [],
];
if($form->isValid()){
$entity->auth();
$result['result'] = true;
} else { // Get ajax errors
$result['errors'] = $symfonyForm->getErrorsArray($form->getErrors(true));
}
echo json_encode($result);
die();
}
$this->arResult['formView'] = $form->createView();
$this->arResult['entity'] = $entity;
$this->