Last active
September 16, 2020 13:45
-
-
Save xTCry/c9f1e94360995c1434c25a67e0699748 to your computer and use it in GitHub Desktop.
Bitrix WebForm (bitrix:form.result.new) template
This file contains 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
<?/*<title>Текст согласия отправки формы</title>*/?> | |
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?> | |
<? | |
$buttonText = (isset($arParams["button"]))? "Нажимая кнопку «".$arParams["button"]."», ": "При отправке формы"; | |
?> | |
<?=$buttonText?> я даю свое согласие на обработку моих персональных данных, в соответствии с Федеральным законом от 27.07.2006 года №152-ФЗ «О персональных данных», на условиях и для целей, определенных в <a href="/html/privacy.php" target="_blank">политике конфиденциальности</a> и <a href="/html/agreement.php" target="_blank">пользовательском соглашении</a> |
This file contains 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
<?$APPLICATION->IncludeComponent( | |
"bitrix:form.result.new", | |
"record_for_consultation", | |
Array( | |
"CACHE_TIME" => "3600", | |
"CACHE_TYPE" => "A", | |
"CHAIN_ITEM_LINK" => "", | |
"CHAIN_ITEM_TEXT" => "", | |
"EDIT_URL" => "", | |
"IGNORE_CUSTOM_TEMPLATE" => "Y", | |
"LIST_URL" => "", | |
"SEF_MODE" => "N", | |
"SUCCESS_URL" => "/include/main/webform_ok.php", | |
"USE_EXTENDED_ERRORS" => "Y", | |
"VARIABLE_ALIASES" => Array("RESULT_ID"=>"RESULT_ID","WEB_FORM_ID"=>"WEB_FORM_ID"), | |
"WEB_FORM_ID" => "1" | |
) | |
);?> |
This file contains 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
// NAME_ID_WEBFORM | |
let NIWF = "#niwf-01"; | |
$(document).ready( function(){ | |
let modal = $(NIWF+' .modal') | |
modalBody = $(NIWF+' .modal .modal-content'), | |
isSure = $(NIWF+' #defaultCheck1'); | |
$(NIWF).on('submit', function (e) { | |
let form = $(this), | |
method = form.attr('method'), | |
action = form.attr('action'), | |
data = form.serialize(); | |
e.preventDefault(); | |
if(!isSure.is(":checked")) { | |
alert("Необходимо согласие"); | |
return; | |
} | |
$.ajax({ | |
type: method, | |
url: action, | |
data: data+"&ajj=true", | |
dataType: "json", | |
success: function(data, status, xhr) { | |
let content = ''; | |
console.log(xhr.getResponseHeader('Location')) | |
$(NIWF+' .form-group > *').removeClass("error"); | |
if(data["error"] != void 0){ | |
let dataError = data["error"]; | |
for(let val in dataError) { | |
$(NIWF+" [name="+val+"]").addClass("error"); | |
content += dataError[val]+'<br>'; | |
} | |
} | |
if(data["note"] != void 0){ | |
content = data["note"]; | |
$(NIWF+' .form-group > *').val(""); | |
} | |
if(content != "") { | |
modalBody.html(content); | |
modal.modal(); | |
} | |
}, | |
error: function(msg){ | |
alert("Ошибка отправки"); | |
}, | |
complete: function(){ | |
Recaptchafree.reset(); | |
console.log("rerender captcha"); | |
} | |
}); | |
}); | |
var _RecaptchafreeSubmitForm = RecaptchafreeSubmitForm; | |
RecaptchafreeSubmitForm = function(token){ | |
if(Recaptchafree.form_submit !== undefined) { | |
var x = document.createElement("INPUT"); | |
x.setAttribute("type", "hidden"); | |
x.name = "g-recaptcha-response"; | |
x.value = token; | |
Recaptchafree.form_submit.appendChild(x); | |
var elements = Recaptchafree.form_submit.elements; | |
for (var i = 0; i < elements.length; i++) { | |
if(elements[i].getAttribute("type") === "submit") { | |
var submit_hidden = document.createElement("INPUT"); | |
submit_hidden.setAttribute("type", "hidden"); | |
submit_hidden.name = elements[i].name; | |
submit_hidden.value = elements[i].value; | |
Recaptchafree.form_submit.appendChild(submit_hidden); | |
} | |
} | |
$(Recaptchafree.form_submit).trigger("submit_ajax"); | |
} | |
}; | |
}); |
This file contains 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
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?> | |
<? | |
if($arResult["isFormNote"] == "Y" && isset($_REQUEST["ajj"])) { | |
$APPLICATION->RestartBuffer(); | |
header('Content-Type: application/json; charset=utf-8'); | |
echo json_encode(["note"=> $arResult["FORM_NOTE"]]); | |
die(); | |
} | |
elseif($arResult["isFormErrors"] == "Y" && isset($_REQUEST["ajj"])) { | |
$APPLICATION->RestartBuffer(); | |
header('Content-Type: application/json; charset=utf-8'); | |
foreach($arResult["QUESTIONS"] as $FIELD_SID => $arQuestion) { | |
$tagName = "form_".$arQuestion["STRUCTURE"][0]["FIELD_TYPE"]."_".$arQuestion["STRUCTURE"][0]["QUESTION_ID"]; | |
if (!is_null($arResult["FORM_ERRORS"][$FIELD_SID])) | |
$arError["error"][$tagName] = $arResult["FORM_ERRORS"][$FIELD_SID]; | |
} | |
echo json_encode($arError); | |
die(); | |
} | |
else if($arResult["isFormNote"] != "Y") {?> | |
<div class="card col-12 col-lg-6 m-auto"> | |
<div class="card-body px-0 px-lg-3 py-lg-3"> | |
<?if ($arResult["isFormTitle"]) { ?> | |
<h4 class="a text-center mb-4"><?=$arResult["FORM_TITLE"]?></h4> | |
<? } ?> | |
<?if ($arResult["isFormDescription"] == "Y") { ?> | |
<div class="f-dsc"><?=$arResult["FORM_DESCRIPTION"]?></div> | |
<? } ?> | |
<form name="<?=$arResult["arForm"]["SID"]?>" action="" method="POST" enctype="multipart/form-data" id="niwf-01"> | |
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="My Modal xT"> | |
<div class="modal-dialog" role="document"> | |
<div class="modal-content"> | |
</div> | |
</div> | |
</div> | |
<input type="hidden" name="sessid" id="sessid" value="<?=bitrix_sessid()?>"> | |
<input type="hidden" name="WEB_FORM_ID" value="<?=$arParams["WEB_FORM_ID"]?>"> | |
<? /*if($arResult["isUseCaptcha"] == "Y") { ?> | |
<tr> | |
<th colspan="2"><b>Капчаа</b></th> | |
</tr> | |
<tr> | |
<td> </td> | |
<td><input type="hidden" name="captcha_sid" value="<?=htmlspecialcharsbx($arResult["CAPTCHACode"]);?>" /><img src="/bitrix/tools/captcha.php?captcha_sid=<?=htmlspecialcharsbx($arResult["CAPTCHACode"]);?>" width="180" height="40" /></td> | |
</tr> | |
<tr> | |
<td>Капча<?=$arResult["REQUIRED_SIGN"];?></td> | |
<td><input type="text" name="captcha_word" size="30" maxlength="50" value="" class="inputtext" /></td> | |
</tr> | |
<? }*/ ?> | |
<? if($arResult["isUseCaptcha"] == "Y") { ?> | |
<input type="hidden" name="captcha_sid" value="<?=$arResult["capCode"]?>"> | |
<img src="/bitrix/tools/captcha.php?captcha_sid=<?=$arResult["capCode"]?>" width="140" height="30" alt="CAPTCHA"> | |
<input type="text" name="captcha_word" size="30" maxlength="50" value="" > | |
<? } ?> | |
<div class="row"> | |
<? | |
$buttonText = htmlspecialcharsbx( (strlen(trim($arResult["arForm"]["BUTTON"])) > 0)? $arResult["arForm"]["BUTTON"]: "Добавить" ); | |
foreach ($arResult["QUESTIONS"] as $FIELD_SID => $arQuestion) { | |
$tagName = "form_".$arQuestion["STRUCTURE"][0]["FIELD_TYPE"]."_".$arQuestion["STRUCTURE"][0]["ID"]; | |
if ($arQuestion['STRUCTURE'][0]['FIELD_TYPE'] == 'hidden') { | |
echo $arQuestion["HTML_CODE"]; | |
} | |
else if ($arQuestion['STRUCTURE'][0]['FIELD_TYPE'] == 'textarea') { | |
$commentTemplate = '<textarea class="form-control" name="'.$tagName.'" rows="3"></textarea> | |
<small id="'.$tagName.'Help" class="form-text text-muted"></small>'; | |
} | |
else { ?> | |
<div class="col-12 col-md-6"> | |
<div class="form-group"> | |
<label for="<?=$tagName?>"> | |
<?if (is_array($arResult["FORM_ERRORS"]) && array_key_exists($FIELD_SID, $arResult['FORM_ERRORS'])) { ?> | |
<span class="error-fld" title="<?=htmlspecialcharsbx($arResult["FORM_ERRORS"][$FIELD_SID])?>"></span> | |
<? } ?> | |
<?=$arQuestion["CAPTION"]?> | |
<?if($arQuestion["REQUIRED"] == "Y") { ?><?=$arResult["REQUIRED_SIGN"];?><? } ?> | |
</label> | |
<input | |
type="<?=$arQuestion["STRUCTURE"][0]["FIELD_TYPE"]?>" | |
class="form-control" | |
name="<?=$tagName?>" | |
placeholder="<?=explode("\n", $arResult["arQuestions"][$FIELD_SID]["COMMENTS"])[0]?>" | |
/> | |
<?=$arQuestion["IS_INPUT_CAPTION_IMAGE"] == "Y" ? "<br />".$arQuestion["IMAGE"]["HTML_CODE"] : ""?> | |
</div> | |
</div> | |
<? } | |
} ?> | |
</div> | |
<?if($commentTemplate) { ?> | |
<div class="form-group"> | |
<label for="exampleFormControlTextarea1">Комментарий</label> | |
<?=$commentTemplate?> | |
</div> | |
<? } ?> | |
<div class="form-check mb-4"> | |
<input class="form-check-input" type="checkbox" value="" id="defaultCheck1" checked="checked" /> | |
<label class="form-check-label tmm" for="defaultCheck1"> | |
<?$APPLICATION->IncludeFile("/include/blocks/form_confidencial_text.php", [ "button"=> $buttonText]);?> | |
</label> | |
</div> | |
<div class="text-center"> | |
<input type="hidden" name="web_form_apply" value="Y" /> | |
<button class="btn btn-danger d-inline-block px-5"> | |
<?=$buttonText?> | |
</button> | |
</div> | |
</form> | |
</div> | |
</div> | |
<? } ?> |
This file contains 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
<? | |
/* Ответ на успешно отправленные формы */ | |
header('Content-Type: application/json; charset=utf-8'); | |
/* | |
$_REQUEST=> | |
formresult: "addok" | |
RESULT_ID: "32" | |
WEB_FORM_ID: "2" | |
*/ | |
if(isset($_REQUEST["formresult"]) && isset($_REQUEST["WEB_FORM_ID"])) { | |
$WFI = $_REQUEST["WEB_FORM_ID"]; | |
$note = ($WFI == 1)? "Ваша заявка успешно отправлена": | |
($WFI == 2)? "Ваш отзыв успешно отправлен": | |
"Успешно"; | |
echo json_encode([ "note"=> $note ]); | |
die(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment