Dodanie walidacji do formy
This commit is contained in:
@@ -33,84 +33,138 @@
|
||||
</div>
|
||||
<? endif;?>
|
||||
<? if ( $this -> client ):?><div class="right"><? endif;?>
|
||||
<form class="form-horizontal" action="/zloz-zamowienie" method="POST" id="form-order">
|
||||
<form class="form-horizontal needs-validation" action="/zloz-zamowienie" method="POST" id="form-order" novalidate>
|
||||
<input type="hidden" name="order_submit_token" value="<?= htmlspecialchars( (string)($this -> order_submit_token ?? ''), ENT_QUOTES, 'UTF-8' );?>">
|
||||
|
||||
<? if ( !$this -> client ):?>
|
||||
<div class="form-group row">
|
||||
<div class="col-12">
|
||||
<input type="email" name="email" class="form-control" required placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'email' ) );?>">
|
||||
<div class="invalid-feedback">
|
||||
Podaj prawidłowy adres e-mail.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? endif;?>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="col-12">
|
||||
<input type="text" id="name" name="name" class="form-control" required placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'imie' ) );?>" value="<?= htmlspecialchars( $address_current['name'] );?>">
|
||||
<div class="invalid-feedback">
|
||||
Podaj imię.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="col-12">
|
||||
<input type="text" id="surname" name="surname" class="form-control" required placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'nazwisko' ) );?>" value="<?= htmlspecialchars( $address_current['surname'] );?>">
|
||||
<div class="invalid-feedback">
|
||||
Podaj nazwisko.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input type="text" id="street" name="street" class="form-control" <? if ( !in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> required<? endif;?> placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'ulica-i-nr-domu' ) );?> <? if ( in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> (<?= \Shared\Helpers\Helpers::lang( 'opcjonalnie' );?>)<? endif;?>" value="<?= htmlspecialchars( $address_current['street'] );?>">
|
||||
<div class="invalid-feedback">
|
||||
Podaj ulicę i numer domu.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6">
|
||||
<input type="text" id="postal_code" name="postal_code" pattern="[0-9]{2}-[0-9]{3}" title="Format xx-xxx" class="form-control" <? if ( !in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> required<? endif;?> placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'kod-pocztowy' ) );?><? if ( in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> (<?= \Shared\Helpers\Helpers::lang( 'opcjonalnie' );?>)<? endif;?>" " value="<?= htmlspecialchars( $address_current['postal_code'] );?>">
|
||||
<input type="text" id="postal_code" name="postal_code" pattern="[0-9]{2}-[0-9]{3}" title="Format xx-xxx" class="form-control" <? if ( !in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> required<? endif;?> placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'kod-pocztowy' ) );?><? if ( in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> (<?= \Shared\Helpers\Helpers::lang( 'opcjonalnie' );?>)<? endif;?>" value="<?= htmlspecialchars( $address_current['postal_code'] );?>">
|
||||
<div class="invalid-feedback">
|
||||
Podaj kod pocztowy w formacie 00-000.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-6">
|
||||
<input type="text" id="city" name="city" class="form-control" <? if ( !in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> required<? endif;?> placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'miasto' ) );?><? if ( in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> (<?= \Shared\Helpers\Helpers::lang( 'opcjonalnie' );?>)<? endif;?>" " value="<?= htmlspecialchars( $address_current['city'] );?>">
|
||||
<input type="text" id="city" name="city" class="form-control" <? if ( !in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> required<? endif;?> placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'miasto' ) );?><? if ( in_array( $this -> transport_method['id'], [ 1, 2, 3, 9] ) ):?> (<?= \Shared\Helpers\Helpers::lang( 'opcjonalnie' );?>)<? endif;?>" value="<?= htmlspecialchars( $address_current['city'] );?>">
|
||||
<div class="invalid-feedback">
|
||||
Podaj miasto.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-control form-control-phone" tooltip="Wprowadź numer w formacie: 123456789">
|
||||
<div class="form-control-phone-code">
|
||||
<img src="/images/system/lang_pl.png" alt="">
|
||||
<span>+48</span>
|
||||
</div>
|
||||
|
||||
<input type="tel" id="phone" name="phone" class="form-control form-control-input" required placeholder="<?= ucfirst(\Shared\Helpers\Helpers::lang('telefon')); ?>" value="<?= htmlspecialchars($address_current['phone']); ?>" pattern="[0-9]{9}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12" id="fvat">
|
||||
<input type="checkbox" name="fvat">
|
||||
<?= \Shared\Helpers\Helpers::lang( 'faktura-vat' );?>
|
||||
<div class="invalid-feedback">
|
||||
Podaj numer telefonu w formacie 123456789.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12" id="fvat">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" name="fvat" id="fvat_checkbox" class="form-check-input">
|
||||
<label class="form-check-label" for="fvat_checkbox">
|
||||
<?= \Shared\Helpers\Helpers::lang( 'faktura-vat' );?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="fvat-data">
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<input type="text" id="firm_name" name="firm_name" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'nazwa-firmy' ) );?>" value="">
|
||||
<input type="text" id="firm_name" name="firm_name" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'nazwa-firmy' ) );?>" value="" data-required-if-fvat="1">
|
||||
<div class="invalid-feedback">
|
||||
Podaj nazwę firmy.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<input type="text" id="firm_street" name="firm_street" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'ulica-i-nr-domu' ) );?>" value="">
|
||||
<input type="text" id="firm_street" name="firm_street" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'ulica-i-nr-domu' ) );?>" value="" data-required-if-fvat="1">
|
||||
<div class="invalid-feedback">
|
||||
Podaj ulicę i numer domu firmy.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6">
|
||||
<input type="text" id="firm_postal_code" name="firm_postal_code" pattern="[0-9]{2}-[0-9]{3}" title="Format xx-xxx" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'kod-pocztowy' ) );?>" value="">
|
||||
<input type="text" id="firm_postal_code" name="firm_postal_code" pattern="[0-9]{2}-[0-9]{3}" title="Format xx-xxx" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'kod-pocztowy' ) );?>" value="" data-required-if-fvat="1">
|
||||
<div class="invalid-feedback">
|
||||
Podaj kod pocztowy firmy w formacie 00-000.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-6">
|
||||
<input type="text" id="firm_city" name="firm_city" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'miasto' ) );?>" value="">
|
||||
<input type="text" id="firm_city" name="firm_city" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'miasto' ) );?>" value="" data-required-if-fvat="1">
|
||||
<div class="invalid-feedback">
|
||||
Podaj miasto firmy.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<input type="text" id="firm_nip" name="firm_nip" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'nip' ) );?>" value="">
|
||||
<input type="text" id="firm_nip" name="firm_nip" class="form-control" placeholder="<?= ucfirst( \Shared\Helpers\Helpers::lang( 'nip' ) );?>" value="" pattern="[0-9]{10}" data-required-if-fvat="1">
|
||||
<div class="invalid-feedback">
|
||||
Podaj NIP w formacie 10 cyfr, bez spacji i myślników.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -119,15 +173,25 @@
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12" id="agreement">
|
||||
<input type="checkbox" name="agreement" required="">
|
||||
<?= \Shared\Helpers\Helpers::lang( 'przeczytalem-i-akceptuje-polityke-prywatnosci-i-regulamin' );?>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" name="agreement" id="agreement_checkbox" class="form-check-input" required>
|
||||
<label class="form-check-label" for="agreement_checkbox">
|
||||
<?= \Shared\Helpers\Helpers::lang( 'przeczytalem-i-akceptuje-polityke-prywatnosci-i-regulamin' );?>
|
||||
</label>
|
||||
<div class="invalid-feedback">
|
||||
Musisz zaakceptować politykę prywatności i regulamin.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-success" id="order-send"><span class="text"><?= ucfirst( \Shared\Helpers\Helpers::lang( 'zamawiam-z-obowiazkiem-zaplaty' ) );?></span></button>
|
||||
<button type="submit" class="btn btn-success" id="order-send">
|
||||
<span class="text"><?= ucfirst( \Shared\Helpers\Helpers::lang( 'zamawiam-z-obowiazkiem-zaplaty' ) );?></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -139,25 +203,74 @@
|
||||
<? if ( $this -> client ):?></div><? endif;?>
|
||||
</div>
|
||||
<script class="footer">
|
||||
$(document).ready(function () {
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
function validatePhone() {
|
||||
var phone = $('#phone');
|
||||
var phonePattern = /^[0-9]{9}$/;
|
||||
window.addEventListener('load', function() {
|
||||
var form = document.getElementById('form-order');
|
||||
|
||||
if (!phone.val() || !phonePattern.test(phone.val())) {
|
||||
$('#order-send').prop('disabled', true);
|
||||
} else {
|
||||
$('#order-send').prop('disabled', false);
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$('#phone').on('input', function () {
|
||||
validatePhone();
|
||||
});
|
||||
var fvatCheckbox = document.getElementById('fvat_checkbox');
|
||||
var fvatRequiredFields = form.querySelectorAll('[data-required-if-fvat="1"]');
|
||||
|
||||
validatePhone();
|
||||
});
|
||||
function updateFvatRequiredFields() {
|
||||
var isRequired = fvatCheckbox && fvatCheckbox.checked;
|
||||
|
||||
Array.prototype.forEach.call(fvatRequiredFields, function(field) {
|
||||
field.required = isRequired;
|
||||
|
||||
if (!isRequired) {
|
||||
field.setCustomValidity('');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (fvatCheckbox) {
|
||||
fvatCheckbox.addEventListener('change', updateFvatRequiredFields);
|
||||
updateFvatRequiredFields();
|
||||
}
|
||||
|
||||
form.addEventListener('submit', function(event) {
|
||||
updateFvatRequiredFields();
|
||||
|
||||
if (form.checkValidity() === false) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
var firstInvalidField = form.querySelector(':invalid');
|
||||
|
||||
if (firstInvalidField) {
|
||||
firstInvalidField.focus();
|
||||
}
|
||||
}
|
||||
|
||||
form.classList.add('was-validated');
|
||||
}, false);
|
||||
}, false);
|
||||
})();
|
||||
|
||||
// $(document).ready(function () {
|
||||
|
||||
// function validatePhone() {
|
||||
// var phone = $('#phone');
|
||||
// var phonePattern = /^[0-9]{9}$/;
|
||||
|
||||
// if (!phone.val() || !phonePattern.test(phone.val())) {
|
||||
// $('#order-send').prop('disabled', true);
|
||||
// } else {
|
||||
// $('#order-send').prop('disabled', false);
|
||||
// }
|
||||
// }
|
||||
|
||||
// $('#phone').on('input', function () {
|
||||
// validatePhone();
|
||||
// });
|
||||
|
||||
// validatePhone();
|
||||
// });
|
||||
|
||||
$( function()
|
||||
{
|
||||
|
||||
@@ -162,17 +162,17 @@
|
||||
var orderForm = document.getElementById('form-order');
|
||||
var orderSendButton = document.getElementById('order-send');
|
||||
|
||||
if (orderForm && orderSendButton) {
|
||||
orderForm.addEventListener('submit', function(event) {
|
||||
if (orderSendButton.disabled) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
// if (orderForm && orderSendButton) {
|
||||
// orderForm.addEventListener('submit', function(event) {
|
||||
// if (orderSendButton.disabled) {
|
||||
// event.preventDefault();
|
||||
// return;
|
||||
// }
|
||||
|
||||
orderSendButton.classList.add('loading-button');
|
||||
orderSendButton.disabled = true;
|
||||
});
|
||||
}
|
||||
// orderSendButton.classList.add('loading-button');
|
||||
// orderSendButton.disabled = true;
|
||||
// });
|
||||
// }
|
||||
<? if ( $this -> settings['google_tag_manager_id'] ):?>
|
||||
dataLayer.push({ ecommerce: null });
|
||||
dataLayer.push({
|
||||
|
||||
Reference in New Issue
Block a user