Commit 0f75b3e2 authored by Shakarim Sapa's avatar Shakarim Sapa

- Правки по подпискам на форму

parent fc89160c
......@@ -55,11 +55,86 @@ if ($cacheEmail!==false && Bid::find()->where(['email' => $cacheEmail])->exists(
</div>
<script type='text/javascript'>
$('form.bids-form').on('submit', function(e) {
var form = $(this);
setInterval(function() {
form.parent('div').fadeOut(500);
}, 1500);
$('form.bids-form').on('beforeSubmit', function(e) {
var form = $(this), xhr = new XMLHttpRequest, filebool = false, file, data = new FormData();
form.find('input, textarea').each(function(){
data.append($(this).attr('name'), $(this).val());
});
if(form.find('input[type=file]').length) {
file = form.find('input[type=file]')[0].files[0];
filebool = !filebool;
data.append("Bid[file]", file);
}
xhr.open("POST", form.attr('action'), true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.send(data);
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4){
try
{
var response = JSON.parse(xhr.responseText);
}
catch(e)
{
var response = xhr.responseText;
}
form.find('.has-error').removeClass('has-error');
if(response.success)
{
if(form.find('.message-box').length > 0)
{
form.find('.message-box').fadeIn('fast');
form.find('.content').css('visibility','hidden');
setTimeout(function(){
form.find('.message-box').fadeOut('fast');
form.find('.content').css('visibility','visible');
}, 2000);
}
form.find('input:not(.not_clear), textarea').val('');
form.find('#files-zone').html('');
$('.dz-preview.dz-processing').remove();
dataLayer.push({
'event': 'UA_event',
'Catagory': form.data('tag'),
'Action': form.data('title'),
'Label': 'Успешно'
});
setInterval(function() {
form.parent('div').fadeOut(500);
}, 1500);
}
else
{
errors = [];
$.each(response, function(key, value) {
form.find('.field-'+key).addClass('has-error');
errors = errors.concat(value);
});
dataLayer.push({
'event': 'UA_event',
'Catagory': 'Ошибки',
'Action': form.data('form'),
'Label': errors
});
}
}
}
}).on('submit', function(e){
return false;
});
</script>
<?php endif; ?>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment