: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
if (options.delegation) {
.off('submit.form-plugin', this.selector, doAjaxSubmit)
.off('click.form-plugin', this.selector, captureSubmittingElement)
.on('submit.form-plugin', this.selector, options, doAjaxSubmit)
.on('click.form-plugin', this.selector, options, captureSubmittingElement);
if (options.beforeFormUnbind) {
options.beforeFormUnbind(this, options);
return this.ajaxFormUnbind()
.on('submit.form-plugin', options, doAjaxSubmit)
.on('click.form-plugin', options, captureSubmittingElement);
// private event handlers
function doAjaxSubmit(e) {
/* jshint validthis:true */
if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
$(e.target).closest('form').ajaxSubmit(options); // #365
function captureSubmittingElement(e) {
/* jshint validthis:true */
if (!$el.is('[type=submit],[type=image]')) {
// is this a child element of the submit el? (ex: a span within a button)
var t = $el.closest('[type=submit]');
if (target.type === 'image') {
if (typeof e.offsetX !== 'undefined') {
} else if (typeof $.fn.offset === 'function') {
var offset = $el.offset();
form.clk_x = e.pageX - offset.left;
form.clk_y = e.pageY - offset.top;
form.clk_x = e.pageX - target.offsetLeft;
form.clk_y = e.pageY - target.offsetTop;
form.clk = form.clk_x = form.clk_y = null;
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
$.fn.ajaxFormUnbind = function() {
return this.off('submit.form-plugin click.form-plugin');
* formToArray() gathers form element data into an array of objects that can
* be passed to any of the following ajax functions: $.get, $.post, or load.
* Each object in the array has both a 'name' and 'value' property. An example of
* an array for a simple login form might be:
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
* It is this array that is passed to pre-submit callback functions provided to the
* ajaxSubmit() and ajaxForm() methods.
$.fn.formToArray = function(semantic, elements, filtering) {
var formId = this.attr('id');
var els = (semantic || typeof form.elements === 'undefined') ? form.getElementsByTagName('*') : form.elements;
els = $.makeArray(els); // convert to standard array
// #386; account for inputs outside the form which use the 'form' attribute
// FinesseRus: in non-IE browsers outside fields are already included in form.elements.
if (formId && (semantic || /(Edge|Trident)\//.test(navigator.userAgent))) {
els2 = $(':input[form="' + formId + '"]').get(); // hat tip @thet
els = (els || []).concat(els2);
if (!els || !els.length) {
if ($.isFunction(filtering)) {
els = $.map(els, filtering);
var i, j, n, v, el, max, jmax;
for (i = 0, max = els.length; i < max; i++) {
if (semantic && form.clk && el.type === 'image') {
// handle image inputs on the fly when semantic == true
a.push({name: n, value: $(el).val(), type: el.type});
a.push({name: n + '.x', value: form.clk_x}, {name: n + '.y', value: form.clk_y});
v = $.fieldValue(el, true);
if (v && v.constructor === Array) {
for (j = 0, jmax = v.length; j < jmax; j++) {
a.push({name: n, value: v[j]});
} else if (feature.fileapi && el.type === 'file') {
for (j = 0; j < files.length; j++) {
a.push({name: n, value: files[j], type: el.type});
a.push({name: n, value: '', type: el.type});
} else if (v !== null && typeof v !== 'undefined') {
a.push({name: n, value: v, type: el.type, required: el.required});
if (!semantic && form.clk) {
// input type=='image' are not found in elements array! handle it here
var $input = $(form.clk), input = $input[0];
if (n && !input.disabled && input.type === 'image') {
a.push({name: n, value: $input.val()});
a.push({name: n + '.x', value: form.clk_x}, {name: n + '.y', value: form.clk_y});
* Serializes form data into a 'submittable' string. This method will return a string
* in the format: name1=value1&name2=value2
$.fn.formSerialize = function(semantic) {
// hand off to jQuery.param for proper encoding
return $.param(this.formToArray(semantic));
* Serializes all field elements in the jQuery object into a query string.
* This method will return a string in the format: name1=value1&name2=value2
$.fn.fieldSerialize = function(successful) {
var v = $.fieldValue(this, successful);
if (v && v.constructor === Array) {
for (var i = 0, max = v.length; i < max; i++) {
a.push({name: n, value: v[i]});
} else if (v !== null && typeof v !== 'undefined') {
a.push({name: this.name, value: v});
// hand off to jQuery.param for proper encoding
* Returns the value(s) of the element in the matched set. For example, consider the following form:
* <input name="A" type="text">
* <input name="A" type="text">
* <input name="B" type="checkbox" value="B1">
* <input name="B" type="checkbox" value="B2">
* <input name="C" type="radio" value="C1">
* <input name="C" type="radio" value="C2">
* var v = $('input[type=text]').fieldValue();
* // if no values are entered into the text inputs
* // if values entered into the text inputs are 'foo' and 'bar'
* var v = $('input[type=checkbox]').fieldValue();
* // if neither checkbox is checked
* // if both checkboxes are checked
* var v = $('input[type=radio]').fieldValue();
* // if neither radio is checked
* // if first radio is checked
* The successful argument controls whether or not the field element must be 'successful'
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
* The default value of the successful argument is true. If this value is false the value(s)
* for each element is returned.
* Note: This method *always* returns an array. If no valid value can be determined the
* array will be empty, otherwise it will contain one or more values.
$.fn.fieldValue = function(successful) {
for (var val = [], i = 0, max = this.length; i < max; i++) {
var v = $.fieldValue(el, successful);
if (v === null || typeof v === 'undefined' || (v.constructor === Array && !v.length)) {
if (v.constructor === Array) {
* Returns the value of the field element.
$.fieldValue = function(el, successful) {
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
if (typeof successful === 'undefined') {
/* eslint-disable no-mixed-operators */
if (successful && (!n || el.disabled || t === 'reset' || t === 'button' ||
(t === 'checkbox' || t === 'radio') && !el.checked ||
(t === 'submit' || t === 'image') && el.form && el.form.clk !== el ||
tag === 'select' && el.selectedIndex === -1)) {
/* eslint-enable no-mixed-operators */
var index = el.selectedIndex;
var a = [], ops = el.options;
var one = (t === 'select-one');
var max = (one ? index + 1 : ops.length);
for (var i = (one ? index : 0); i < max; i++) {
if (op.selected && !op.disabled) {
if (!v) { // extra pain for IE...
v = (op.attributes && op.attributes.value && !(op.attributes.value.specified)) ? op.text : op.value;
return $(el).val().replace(rCRLF, '\r\n');
* Clears the form data. Takes the following actions on the form's input fields:
* - input text fields will have their 'value' property set to the empty string
* - select elements will have their 'selectedIndex' property set to -1
* - checkbox and radio inputs will have their 'checked' property set to false
* - inputs of type submit, button, reset, and hidden will *not* be effected
* - button elements will *not* be effected
$.fn.clearForm = function(includeHidden) {
return this.each(function() {
$('input,select,textarea', this).clearFields(includeHidden);
* Clears the selected form elements.
$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
return this.each(function() {
var t = this.type, tag = this.tagName.toLowerCase();
if (re.test(t) || tag === 'textarea') {
} else if (t === 'checkbox' || t === 'radio') {
} else if (tag === 'select') {
} else if (t === 'file') {
if (/MSIE/.test(navigator.userAgent)) {
$(this).replaceWith($(this).clone(true));
} else if (includeHidden) {
// includeHidden can be the value true, or it can be a selector string
// indicating a special test; for example:
// $('#myForm').clearForm('.special:hidden')
// the above would clean hidden inputs that have the class of 'special'
if ((includeHidden === true && /hidden/.test(t)) ||
(typeof includeHidden === 'string' && $(this).is(includeHidden))) {
* Resets the form data or individual elements. Takes the following actions
* - all fields within form elements will be reset to their original value
* - input / textarea / select fields will be reset to their original value
* - option / optgroup fields (for multi-selects) will defaulted individually
* - non-multiple options will find the right select to default
* - label elements will be searched against its 'for' attribute
* - all others will be searched for appropriate children to default
$.fn.resetForm = function() {
return this.each(function() {
var tag = this.tagName.toLowerCase();
this.checked = this.defaultChecked;
this.value = this.defaultValue;
var select = el.parents('select');
if (select.length && select[0].multiple) {
this.selected = this.defaultSelected;
el.find('option').resetForm();
el.find('option').each(function(i) { // eslint-disable-line consistent-return
this.selected = this.defaultSelected;
if (this.defaultSelected && !el[0].multiple) {
var forEl = $(el.attr('for'));
var list = el.find('input,select,textarea');
// guard against an input with the name of 'reset'
// note that IE reports the reset function as an 'object'
if (typeof this.reset === 'function' || (typeof this.reset === 'object' && !this.reset.nodeType)) {
el.find('form,input,label,select,textarea').resetForm();
* Enables or disables any matching elements.
$.fn.enable = function(b) {
if (typeof b === 'undefined') {
return this.each(function() {
* Checks/unchecks any matching checkboxes or radio buttons and
* selects/deselects and matching option elements.
$.fn.selected = function(select) {
if (typeof select === 'undefined') {