PHP code example of proklung / bitrix-webform-bundle

1. Go to this page and download the library: Download proklung/bitrix-webform-bundle 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/ */

    

proklung / bitrix-webform-bundle example snippets


use Prokl\BitrixWebformBundle\Services\Migrations\CreateWebForm;

/**
 * @var CreateWebForm $creator
 */
$creator = container()->get('bitrix_form_bundle.create_form');

$creator->deleteFormByCode('TESTING_FORM');
$creator->setNameForm('Тестировочная форма')
        ->setMenuItem(['ru' => 'Тестировочная форма', 'en' => 'Testing'])
        ->setSort(1000)
        ->setSidForm('TESTING_FORM')
        ->createForm()
        ->addTextField('EMAIL', 'Электронный адрес')
        ->addRadioButtonYesNow('RIGHTS', 'Вы гуманоид?')
        ->addTextField('NAME', 'Ваше имя')
        ->addTextareaField('COMMENTS', 'Комментарии')
        ->addDropdown('DROPS', 'Список', [
            'LIST1', 'LIST2'
        ])
        ->addQuestions()
        ->createEmailTemplate()
        ->createStatus();

use Prokl\BitrixWebformBundle\Services\FormProcessor;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class FormController extends AbstractController
{
  public function action(Request $request, FormProcessor $processor) : Response 
  {
      $params = $request->request->all();
      $result = $processor->setFormCode('TESTING_FORM')
                          ->setData($params)
                          ->processForm();

      return new Response(['id_answer' => $result]);  
  
  }
}

use Prokl\BitrixWebformBundle\Services\FormSearcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class FormController extends AbstractController
{
  public function action(Request $request, FormSearcher $searcher) : Response 
  {
        /**
        $params = [
            'NAME' => '1111',
            'EMAIL' => '[email protected]',
        ];
       */
      $params = $request->request->all();
       
      $result = $searcher->addFilter($params)
                          ->setIdForm(8) // Допустимо использовать setFormCode('Символьный код формы')
                          ->exist();
        
      return new Response(['already_exists' => $result]);  
  
  }
}

html
<pre>array (
     *   [WEB_FORM_ID] => 3
     *   [web_form_submit] => Отправить
     *
     *   [form_text_18] => aafafsfasdf
     *   [form_text_19] => q1241431342
     *   [form_text_21] => afsafasdfdsaf
     *   [form_textarea_20] =>
     *   [form_text_22] => fasfdfasdf
     *   [form_text_23] => 31243123412
     *
     *   18, 19, 21 - ID ответов у вопросов
     *   )</pre>