Created
April 14, 2025 13:17
-
-
Save EscApp2/50ea76673c75b9b5c927ed2c71a45da0 to your computer and use it in GitHub Desktop.
form
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
| \Bitrix\Main\Loader::IncludeModule("form"); | |
| CForm::GetResultAnswerArray($WEB_FORM_ID, | |
| $arrColumns, | |
| $arrAnswers, | |
| $arrAnswersVarname, | |
| array()); | |
| $arFormResult = array(); | |
| $is_filtered = null; | |
| $CHECK_RIGHTS = "N"; | |
| $records_limit = false; | |
| $resForm = CFormResult::GetList($WEB_FORM_ID, $by, $order , $arFilter, $is_filtered, $CHECK_RIGHTS, $records_limit); | |
| while($arForm = $resForm->fetch()){ | |
| $arResult = array( | |
| "ID"=>$arForm['ID'], | |
| ); | |
| foreach($arrColumns as $arColumn){ | |
| $CODE = $arColumn['SID']; | |
| $NAME = $arColumn['TITLE']; | |
| $arAnswerList = $arrAnswers[$arForm['ID']][$arColumn['ID']]; | |
| $arOneAnswerResult = array(); | |
| foreach($arAnswerList as $arOneAnswer){ | |
| $arOneAnswerResult[] = $arOneAnswer['USER_TEXT']; | |
| } | |
| $arResult[$CODE] = implode("/",$arOneAnswerResult); | |
| } | |
| $arFormResult[$arForm['ID']] = $arResult; | |
| } |
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
| public static function sendFormResultV2($arrSourceFields) { | |
| $result = array( | |
| 'result' => false, | |
| 'errors' => array() | |
| ); | |
| //$arrFields = array_column($arrSourceFields, 'value', 'name'); | |
| $arrFields = $arrSourceFields; | |
| if(isMultiLevelArray($arrFields)){ | |
| $arrFields = $arrFields[0]; | |
| } | |
| $WEB_FORM_ID = $arrFields['WEB_FORM_ID']; | |
| if($WEB_FORM_ID){ | |
| \Bitrix\Main\Loader::IncludeModule("form"); | |
| $arResult = array(); | |
| $arResult["arForm"] = array(); | |
| $arResult["arQuestions"] = array(); | |
| $arResult["arAnswers"] = array(); | |
| $arResult["arDropDown"] = array(); | |
| $arResult["arMultiSelect"] = array(); | |
| CForm::GetDataByID($WEB_FORM_ID, | |
| $arResult["arForm"], $arResult["arQuestions"], | |
| $arResult["arAnswers"], $arResult["arDropDown"], | |
| $arResult["arMultiSelect"], | |
| "N"); | |
| $arrRequired = array(); | |
| $formFields = array(); | |
| foreach($arResult['arQuestions'] as $CODE=>$arQuestion){ | |
| $FIRST_ANSWER_FIELD_ID = $arResult['arAnswers'][$CODE][0]['ID']; | |
| $FIRST_ANSWER_FIELD_TYPE = $arResult['arAnswers'][$CODE][0]['FIELD_TYPE']; | |
| $FIRST_ANSWER_NAME = "form_".$FIRST_ANSWER_FIELD_TYPE."_".$FIRST_ANSWER_FIELD_ID; | |
| if("Y"==$arQuestion['REQUIRED']){ | |
| $arrRequired[] = $FIRST_ANSWER_NAME; | |
| } | |
| $formFields[$FIRST_ANSWER_NAME] = $arrFields[$FIRST_ANSWER_NAME]; | |
| } | |
| $requiredCheck = true; | |
| foreach ($arrRequired as $fieldName) { | |
| if (empty($arrFields[$fieldName])) { | |
| $requiredCheck = false; | |
| $result['errors'][] = 'field ' . $fieldName . ' is empty!'; | |
| } | |
| } | |
| //$result['f'] = $arrFields; | |
| $captchaRes = checkRecaptcha3(R3_SECRETKEY, $arrFields['recaptchaResponse'], $_SERVER['REMOTE_ADDR']); | |
| if(!$captchaRes){ | |
| //$requiredCheck = false; | |
| } | |
| if ($requiredCheck) { | |
| $resId = \CFormResult::Add($WEB_FORM_ID, | |
| $formFields | |
| ); | |
| if ($resId) { | |
| \CFormCRM::onResultAdded($WEB_FORM_ID, $resId); | |
| \CFormResult::SetEvent($resId); | |
| \CFormResult::Mail($resId); | |
| $result['result'] = true; | |
| } else { | |
| global $strError; | |
| $result['errors'][] = $strError; | |
| } | |
| } | |
| } | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment