Last active
July 20, 2020 18:31
-
-
Save zaurmag/4302f7a4325a573630f7a0b596d44e34 to your computer and use it in GitHub Desktop.
Ajax отправка формы для RSFORM
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
/* ============================= | |
Ajax Submit Form Plugin | |
Форма может скрываться на 4 секунды после отправки. Для этого оберните форму родительским блоком с классом - hide-form-success | |
=============================================================== */ | |
(function($) { | |
jQuery.fn.sendForm = function(options) { | |
options = $.extend({ | |
successTitle: "Ваше сообщение успешно отправлено!", | |
successText: "Мы свяжемся с Вами в самое ближайшее время" | |
}, options); | |
var make = function() { | |
var optionsForm = { | |
beforeSubmit: showRequest, | |
success: showResponseAll | |
}; | |
// bind to the form's submit event | |
$(this).submit(function() { | |
$(this).ajaxSubmit(optionsForm); | |
return false; | |
}); | |
var $this = $(this); | |
// pre-submit callback | |
function showRequest(formData, jqForm, options) { | |
$this.find('.rsform-submit-button').addClass('sending').text("Отправка...."); | |
} | |
// post-submit callback | |
function showResponseAll(responseText, statusText, xhr, $form) { | |
if ($this.find('.formError').is(":visible")) { | |
$this.find('.rsform-submit-button').removeClass('sending').text("Отправить"); | |
} else { | |
$this[0].reset(); | |
$this.find('.hide-form-success').slideUp().delay(4000).slideDown(); | |
$this.find('.rsform-submit-button').removeClass('sending').text("Отправить"); | |
$this.find('.hide-form-success').after('<div class="sys-messages"></div>'); | |
$this.find('.sys-messages').html('<h5 class="success-title">' + options.successTitle + '</h5><p class = "success-text" >' + options.successText + '</p>'); | |
setTimeout(function() { | |
$this.find('.sys-messages').fadeOut().delay(2000).remove(); | |
}, 4000); | |
} | |
} | |
} | |
return this.each(make); | |
}; | |
})(jQuery); | |
/* ============================================================= | |
C собственной валидацией (валидация RsForm должна быть отключена) для версии - 1.52++ | |
Обязательное поле input надо обязательно обернуть родительским блоком с классом - required-field | |
============================================================================================================== */ | |
// ======= Ajax Submit Form Plugin ======= | |
(function($) { | |
jQuery.fn.sendForm = function(options) { | |
options = $.extend({ | |
successTitle: "Ваше сообщение успешно отправлено!", | |
successText: "Мы свяжемся с Вами в самое ближайшее время" | |
}, options); | |
var make = function() { | |
var optionsForm = { | |
beforeSubmit: showRequest, | |
success: showResponseAll | |
}; | |
// bind to the form's submit event | |
$(this).submit(function() { | |
$(this).ajaxSubmit(optionsForm); | |
return false; | |
}); | |
var $this = $(this); | |
// pre-submit callback | |
function showRequest(formData, jqForm, options) { | |
$this.find('.rsform-submit-button').addClass('sending').text("Отправка...."); | |
} | |
// Validation Fields | |
var requiredField = $this.find('.required-field input'); | |
requiredField.change(function() { | |
$(this).next().hide(); | |
$(this).removeClass('rsform-error'); | |
}); | |
// post-submit callback | |
function showResponseAll(responseText, statusText, xhr, $form) { | |
if ($this.find('.formError').is(":visible")) { | |
$this.find('.rsform-submit-button').removeClass('sending').text("Отправить"); | |
} else if ($this.find('.required-field input').val() == '') { | |
requiredField.addClass('rsform-error'); | |
requiredField.next().addClass('formError').show(); | |
$this.find('.rsform-submit-button').removeClass('sending').text("Отправить"); | |
} else { | |
$this[0].reset(); | |
$this.find('.hide-form-success').slideUp().delay(4000).slideDown(); | |
$this.find('.rsform-submit-button').removeClass('sending').text("Отправить"); | |
$this.find('.hide-form-success').after('<div class="sys-messages"></div>'); | |
$this.find('.sys-messages').html('<h5 class="success-title">' + options.successTitle + '</h5><p class = "success-text" >' + options.successText + '</p>'); | |
setTimeout(function() { | |
$this.find('.sys-messages').fadeOut().delay(2000).remove(); | |
}, 4000); | |
} | |
} | |
} | |
return this.each(make); | |
}; | |
})(jQuery); |
Hello, How to use this plugin?
Read here - https://zaurmag.ru/joomla/ajax-otpravka-formy-bez-perezagruzki-stranitsy.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, How to use this plugin?