Created
July 21, 2017 04:48
-
-
Save roketstorm/7ee2c442fa1c933edcb47e25301f7abd to your computer and use it in GitHub Desktop.
Bitrix web-form 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
<? | |
/** @var array $arParams */ | |
/** @var array $arResult */ | |
?> | |
<? | |
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die(); | |
?> | |
<form name="<?=$arResult["WEB_FORM_NAME"]?>" action="<?=POST_FORM_ACTION_URI;?>" enctype="multipart/form-data" method="POST"> | |
<?=bitrix_sessid_post();?> | |
<input type="hidden" name="WEB_FORM_ID" value="<?=$arParams["WEB_FORM_ID"];?>" /> | |
<input type="hidden" name="lang" value="ru" /> | |
<?// Ошибка при отправке формы //?> | |
<?if ($arResult["isFormErrors"] == "Y"):?> | |
<div class="form-result form-fail"> | |
<div class="form-result-text"> | |
Ошибка при отправке | |
</div> | |
</div> | |
<?endif;?> | |
<?//-- Тело формы --//?> | |
<?if ($arResult["isFormNote"] != "Y"):?> | |
<?//-- Вывод полей формы --//?> | |
<?foreach ($arResult["QUESTIONS"] as $FIELD_SID => $arQuestion):?> | |
<? | |
$inputError = !empty($arResult["FORM_ERRORS"][$FIELD_SID]) ? "Y" : "N"; | |
$inputSuccess = !empty($arResult["FORM_ERRORS"]) && empty($arResult["FORM_ERRORS"][$FIELD_SID]) ? "Y" : "N"; | |
// Будет пустым если поле не заполнено или форма ещё не отправлялась хотябы 1 раз | |
$inputValue = $arResult["arrVALUES"]["form_".$arQuestion["STRUCTURE"][0]["FIELD_TYPE"]."_".$arQuestion["STRUCTURE"][0]["ID"]]; | |
switch($arQuestion["STRUCTURE"][0]["FIELD_TYPE"]) | |
{ | |
case 'text';?> | |
<?// Text and Phone //?> | |
<?if($arResult["arQuestions"][$FIELD_SID]["COMMENTS"] == "js_phone_input"):?> | |
<?// Телефон //?> | |
<div class="field<?if($inputError == "Y"):?> fail<?elseif($inputSuccess == "Y"):?> success<?endif;?>"> | |
<label for="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>"> | |
<?=$arQuestion['CAPTION']?> | |
</label> | |
<input | |
class="text-input js-phone-mask" | |
type="text" | |
name="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
id="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
<?if($arQuestion["REQUIRED"] == "Y"):?>required="required"<?endif;?> | |
placeholder="8 (***) ***-**-**" | |
value="<?=$inputValue?>" | |
/> | |
<?if($inputError == "Y"):?> | |
<div class="input-comment"><?=$arResult["FORM_ERRORS"][$FIELD_SID]?></div> | |
<?endif;?> | |
</div> | |
<script> | |
$(function () {$(".js-phone-mask").mask("8 (999) 999-99-99");}); | |
</script> | |
<?elseif($arResult["arQuestions"][$FIELD_SID]["COMMENTS"] == "system_product_id"):?> | |
<?// Системное поле с ID продукта //?> | |
<div class="field" style="display: none;"> | |
<label for="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>"> | |
<?=$arQuestion['CAPTION']?> | |
</label> | |
<input | |
type="text" | |
class="text-input" | |
name="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
id="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
placeholder="<?=$arResult["arQuestions"][$FIELD_SID]["COMMENTS"]?>" | |
value="<?=$arParams["PRODUCT_ID"]?>" | |
/> | |
</div> | |
<?elseif($arResult["arQuestions"][$FIELD_SID]["COMMENTS"] == "system_product_name"):?> | |
<?// Системное поле с NAME продукта //?> | |
<div class="field" style="display: none;"> | |
<label for="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>"> | |
<?=$arQuestion['CAPTION']?> | |
</label> | |
<input | |
type="text" | |
class="text-input" | |
name="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
id="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
placeholder="<?=$arResult["arQuestions"][$FIELD_SID]["COMMENTS"]?>" | |
value="<?=$arParams["PRODUCT_NAME"]?>" | |
/> | |
</div> | |
<?else:?> | |
<?// Текстовое поле //?> | |
<div class="field<?if($inputError == "Y"):?> fail<?elseif($inputSuccess == "Y"):?> success<?endif;?>"> | |
<label for="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>"> | |
<?=$arQuestion['CAPTION']?> | |
</label> | |
<input | |
type="text" | |
class="text-input" | |
name="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
id="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
<?if($arQuestion["REQUIRED"] == "Y"):?>required="required"<?endif;?> | |
placeholder="<?=$arResult["arQuestions"][$FIELD_SID]["COMMENTS"]?>" | |
value="<?=$inputValue?>" | |
/> | |
<?if($inputError == "Y"):?> | |
<div class="input-comment"><?=$arResult["FORM_ERRORS"][$FIELD_SID]?></div> | |
<?endif;?> | |
</div> | |
<?endif;?> | |
<?break;?> | |
<?case 'email';?> | |
<?// E-mail //?> | |
<div class="field<?if($inputError == "Y"):?> fail<?elseif($inputSuccess == "Y"):?> success<?endif;?>"> | |
<label for="form_email_<?=$arQuestion["STRUCTURE"][0]["ID"]?>"> | |
<?=$arQuestion['CAPTION']?> | |
</label> | |
<input | |
class="text-input" | |
type="email" | |
name="form_email_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
id="form_email_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
<?if($arQuestion["REQUIRED"] == "Y"):?>required="required"<?endif;?> | |
placeholder="<?=$arResult["arQuestions"][$FIELD_SID]["COMMENTS"]?>" | |
value="<?=$inputValue?>" | |
/> | |
<?if($inputError == "Y"):?> | |
<div class="input-comment"><?=$arResult["FORM_ERRORS"][$FIELD_SID]?></div> | |
<?endif;?> | |
</div> | |
<?break;?> | |
<?case 'textarea';?> | |
<?// Textarea //?> | |
<div class="field<?if($inputError == "Y"):?> fail<?elseif($inputSuccess == "Y"):?> success<?endif;?>"> | |
<label for="form_textarea_<?=$arQuestion["STRUCTURE"][0]["ID"]?>"> | |
<?=$arQuestion['CAPTION']?> | |
</label> | |
<textarea | |
class="text-input" | |
name="form_textarea_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
id="form_textarea_<?=$arQuestion["STRUCTURE"][0]["ID"]?>" | |
<?if($arQuestion["REQUIRED"] == "Y"):?>required="required"<?endif;?> | |
placeholder="<?=$arResult["arQuestions"][$FIELD_SID]["COMMENTS"]?>" | |
><?=$inputValue?></textarea> | |
<?if($inputError == "Y"):?> | |
<div class="input-comment"><?=$arResult["FORM_ERRORS"][$FIELD_SID]?></div> | |
<?endif;?> | |
</div> | |
<?break;?> | |
<?case 'checkbox';?> | |
<?// Checkbox //?> | |
<div class="field<?if($inputError == "Y"):?> fail<?elseif($inputSuccess == "Y"):?> success<?endif;?>"> | |
<input | |
type="checkbox" | |
name="form_checkbox_<?=$FIELD_SID?>[]" | |
id="form_checkbox_<?=$arResult["arAnswers"][$FIELD_SID][0]["ID"]?>" | |
<?if($arQuestion["REQUIRED"] == "Y"):?>required="required"<?endif;?> | |
placeholder="<?=$arResult["arQuestions"][$FIELD_SID]["COMMENTS"]?>" | |
value="<?=$arResult["arAnswers"][$FIELD_SID][0]["ID"]?>" | |
/> | |
<label for="form_checkbox_<?=$arResult["arAnswers"][$FIELD_SID][0]["ID"]?>"> | |
<?=$arQuestion['CAPTION']?> | |
</label> | |
<?if($inputError == "Y"):?> | |
<div class="input-comment"><?=$arResult["FORM_ERRORS"][$FIELD_SID]?></div> | |
<?endif;?> | |
</div> | |
<script> | |
$(document).ready(function () { | |
$('#form_checkbox_<?=$arQuestion["STRUCTURE"][0]["ID"]?>').click(function () | |
{ | |
$('#form_checkbox_<?=$arQuestion["STRUCTURE"][0]["ID"]?>').change(function () { | |
$('#js-btncheck').prop("disabled", !this.checked); | |
}).change(); | |
}); | |
}); | |
</script> | |
<?break;?> | |
<? | |
}?> | |
<?endforeach;?> | |
<?//-- Captcha --//?> | |
<?if($arResult["isUseCaptcha"] == "Y"):?> | |
<? | |
$captchaError = !empty($arResult["FORM_ERRORS"][0]) ? "Y" : "N"; | |
$captchaSuccess = !empty($arResult["FORM_ERRORS"]) && empty($arResult["FORM_ERRORS"][0]) ? "Y" : "N"; | |
?> | |
<div class="field<?if($captchaError == "Y"):?> fail<?elseif($captchaSuccess == "Y"):?> success<?endif;?>"> | |
<label for="form_text_<?=$arQuestion["STRUCTURE"][0]["ID"]?>"> | |
<?=GetMessage("FORM_CAPTCHA_FIELD_TITLE")?> <span class="starrequired">*</span> | |
</label> | |
<input type="hidden" name="captcha_sid" value="<?=htmlspecialcharsbx($arResult["CAPTCHACode"]);?>" /> | |
<img src="/bitrix/tools/captcha.php?captcha_sid=<?=htmlspecialcharsbx($arResult["CAPTCHACode"]);?>" width="200" height="40" /> | |
<br /> | |
<br /> | |
<input class="text-input" type="text" name="captcha_word" maxlength="50" value="" required="required"/> | |
<?if($captchaError == "Y"):?> | |
<div class="input-comment"><?=$arResult["FORM_ERRORS"][0]?></div> | |
<?endif;?> | |
</div> | |
<?endif;?> | |
<?//-- Кнопки --//?> | |
<div class="button-area"> | |
<button type="submit" | |
class="button-default" | |
name="web_form_submit" | |
value="<?=$arResult["arForm"]["BUTTON"]?>"> | |
<?=$arResult["arForm"]["BUTTON"]?> | |
</button> | |
<input type="hidden" name="web_form_apply" value="Y" /> | |
</div> | |
<?endif;?> | |
<?//-- Успешная отправка формы --//?> | |
<?if(!empty($arResult["FORM_NOTE"])):?> | |
<div class="form-result form-success"> | |
<div class="form-result-text"> | |
Успешно отправлено! | |
</div> | |
</div> | |
<?endif;?> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment