: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wpforms_builder_providers, wpforms_builder, wpf */
spinner: '<i class="wpforms-loading-spinner wpforms-loading-inline"></i>',
spinnerWhite: '<i class="wpforms-loading-spinner wpforms-loading-inline wpforms-loading-white"></i>',
$( WPFormsProviders.ready );
WPFormsProviders.bindUIActions();
// Setup/cache some vars not available before.
s.form = $( '#wpforms-builder-form' );
bindUIActions: function() {
$( document ).on( 'click', '.wpforms-provider-connection-delete', function( e ) {
WPFormsProviders.connectionDelete( this, e );
$( document ).on( 'click', '.wpforms-provider-connections-add', function( e ) {
WPFormsProviders.connectionAdd( this, e );
// Add new provider account.
$( document ).on( 'click', '.wpforms-provider-account-add button', function( e ) {
WPFormsProviders.accountAdd( this, e );
// Select provider account.
$( document ).on( 'change', '.wpforms-provider-accounts select', function( e ) {
WPFormsProviders.accountSelect( this, e );
$( document ).on( 'change', '.wpforms-provider-lists select', function( e ) {
WPFormsProviders.accountListSelect( this, e );
$( document ).on( 'wpformsPanelSwitch', function( e, targetPanel ) {
WPFormsProviders.providerPanelConfirm( targetPanel );
// Alert users if they save a form and do not configure required
$( document ).on( 'wpformsSaved', function() {
var $connectionBlocks = $( '#wpforms-panel-providers' ).find( '.wpforms-connection-block' );
if ( ! $connectionBlocks.length ) {
$connectionBlocks.each( function() {
var requiredEmpty = false,
$( this ).find( 'table span.required' ).each( function() {
var $element = $( this ).parent().parent().find( 'select' );
if ( $element.val() === '' ) {
var $titleArea = $( this ).closest( '.wpforms-panel-content-section' ).find( '.wpforms-panel-content-section-title' ).clone();
$titleArea.find( 'button' ).remove();
providerName = $titleArea.text().trim();
var msg = wpforms_builder.provider_required_flds;
if ( -1 < providerAlerts.indexOf( providerName ) ) {
title: wpforms_builder.heads_up,
content: msg.replace( '{provider}', providerName ),
icon: 'fa fa-exclamation-circle',
text: wpforms_builder.ok,
providerAlerts.push( providerName );
* Delete provider connection
connectionDelete: function( el, e ) {
content: wpforms_builder_providers.confirm_connection,
icon: 'fa fa-exclamation-circle',
text: wpforms_builder.ok,
var $section = $this.closest( '.wpforms-panel-content-section' );
$this.closest( '.wpforms-provider-connection' ).remove();
if ( ! $section.find( '.wpforms-provider-connection' ).length ) {
$section.find( '.wpforms-builder-provider-connections-default' ).removeClass( 'wpforms-hidden' );
text: wpforms_builder.cancel,
* Add new provider connection.
connectionAdd: function( el, e ) {
$connections = $this.parent().parent(),
$container = $this.parent(),
provider = $this.data( 'provider' ),
type = $this.data( 'type' ),
namePrompt = wpforms_builder_providers.prompt_connection,
nameField = '<input autofocus="" type="text" id="provider-connection-name" placeholder="' + wpforms_builder_providers.prompt_placeholder + '">',
nameError = '<p class="error">' + wpforms_builder_providers.error_name + '</p>',
modalContent = namePrompt + nameField + nameError;
modalContent = modalContent.replace( /%type%/g, type );
icon: 'fa fa-info-circle',
text: wpforms_builder.ok,
var name = this.$content.find( 'input#provider-connection-name' ).val().trim();
var error = this.$content.find( '.error' );
WPFormsProviders.inputToggle( $this, 'disable' );
action : 'wpforms_provider_ajax_' + provider,
id : s.form.data( 'id' ),
nonce : wpforms_builder.nonce,
WPFormsProviders.fireAJAX( $this, data, function( res ) {
$connections.find( '.wpforms-builder-provider-connections-default' ).addClass( 'wpforms-hidden' );
$connections.find( '.wpforms-provider-connections' ).prepend( res.data.html );
// Process and load the accounts if they exist.
var $connection = $connections.find( '.wpforms-provider-connection' ).first();
if ( $connection.find( '.wpforms-provider-accounts option:selected' ) ) {
$connection.find( '.wpforms-provider-accounts option' ).first().prop( 'selected', true );
$connection.find( '.wpforms-provider-accounts select' ).trigger( 'change' );
WPFormsProviders.errorDisplay( res.data.error, $container );
text: wpforms_builder.cancel,
* Add and authorize provider account.
accountAdd: function( el, e ) {
provider = $this.data( 'provider' ),
$connection = $this.closest( '.wpforms-provider-connection' ),
$container = $this.parent(),
$fields = $container.find( ':input' ),
errors = WPFormsProviders.requiredCheck( $fields, $container );
WPFormsProviders.inputToggle( $this, 'disable' );
// Bail if we have any errors.
$this.prop( 'disabled', false ).find( 'i' ).remove();
action : 'wpforms_provider_ajax_' + provider,
connection_id: $connection.data( 'connection_id' ),
data : WPFormsProviders.fakeSerialize( $fields ),
WPFormsProviders.fireAJAX( $this, data, function( res ) {
$container.nextAll( '.wpforms-connection-block' ).remove();
$container.nextAll( '.wpforms-conditional-block' ).remove();
$container.after( res.data.html );
$connection.find( '.wpforms-provider-accounts select' ).trigger( 'change' );
WPFormsProviders.errorDisplay( res.data.error, $container );
* Selecting a provider account
accountSelect: function( el, e ) {
$connection = $this.closest( '.wpforms-provider-connection' ),
$container = $this.parent(),
provider = $connection.data( 'provider' );
// Disable select, show loading.
WPFormsProviders.inputToggle( $this, 'disable' );
// Remove any blocks that might exist as we prep for new account.
$container.nextAll( '.wpforms-connection-block' ).remove();
$container.nextAll( '.wpforms-conditional-block' ).remove();
// User selected to option to add new account.
$connection.find( '.wpforms-provider-account-add input' ).val( '' );
$connection.find( '.wpforms-provider-account-add' ).slideDown();
WPFormsProviders.inputToggle( $this, 'enable' );
$connection.find( '.wpforms-provider-account-add' ).slideUp();
action : 'wpforms_provider_ajax_' + provider,
connection_id: $connection.data( 'connection_id' ),
account_id : $this.find( ':selected' ).val(),
WPFormsProviders.fireAJAX( $this, data, function( res ) {
$container.after( res.data.html );
// Process first list found.
$connection.find( '.wpforms-provider-lists option' ).first().prop( 'selected', true );
$connection.find( '.wpforms-provider-lists select' ).trigger( 'change' );
WPFormsProviders.errorDisplay( res.data.error, $container );
* Selecting a provider account list.
accountListSelect: function( el, e ) {
$connection = $this.closest( '.wpforms-provider-connection' ),
$container = $this.parent(),
provider = $connection.data( 'provider' );
// Disable select, show loading.
WPFormsProviders.inputToggle( $this, 'disable' );
// Remove any blocks that might exist as we prep for new account.
$container.nextAll( '.wpforms-connection-block' ).remove();
$container.nextAll( '.wpforms-conditional-block' ).remove();
action : 'wpforms_provider_ajax_' + provider,
connection_id: $connection.data( 'connection_id' ),
account_id : $connection.find( '.wpforms-provider-accounts option:selected' ).val(),
list_id : $this.find( ':selected' ).val(),
form_id : s.form.data( 'id' ),
WPFormsProviders.fireAJAX( $this, data, function( res ) {
$container.after( res.data.html );
// Re-init tooltips for new fields.
WPFormsProviders.errorDisplay( res.data.error, $container );
* Confirm form save before loading Provider panel.
* If confirmed, save and reload panel.
providerPanelConfirm: function( targetPanel ) {
wpforms_panel_switch = true;
if ( targetPanel === 'providers' && ! s.form.data( 'revision' ) ) {
if ( wpf.savedState != wpf.getFormState( '#wpforms-builder-form' ) ) {
wpforms_panel_switch = false;
content: wpforms_builder_providers.confirm_save,
icon: 'fa fa-info-circle',
text: wpforms_builder.ok,
$( '#wpforms-save' ).trigger( 'click' );
$( document ).on( 'wpformsSaved', function() {
window.location.href = wpforms_builder_providers.url;
text: wpforms_builder.cancel,
//--------------------------------------------------------------------//
//--------------------------------------------------------------------//
fireAJAX: function( el, d, success ) {
id : $( '#wpforms-builder-form' ).data( 'id' ),
nonce : wpforms_builder.nonce,
$.post( wpforms_builder.ajax_url, data, function( res ) {
WPFormsProviders.inputToggle( $this, 'enable' );
} ).fail( function( xhr, textStatus, e ) {
console.log( xhr.responseText );
* Toggle input with loading indicator.
inputToggle: function( el, status ) {
if ( status === 'enable' ) {
if ( $this.is( 'select' ) ) {
$this.prop( 'disabled', false ).next( 'i' ).remove();
$this.prop( 'disabled', false ).find( 'i' ).remove();
} else if ( status === 'disable' ) {
if ( $this.is( 'select' ) ) {
$this.prop( 'disabled', true ).after( s.spinner );
$this.prop( 'disabled', true ).prepend( s.spinnerWhite );
errorDisplay: function( msg, location ) {
location.find( '.wpforms-error-msg' ).remove();
location.prepend( '<p class="wpforms-alert-danger wpforms-alert wpforms-error-msg">' + msg + '</p>' );
* Check for required fields.
requiredCheck: function( fields, location ) {
// Remove any previous errors.
location.find( '.wpforms-alert-required' ).remove();
// Loop through input fields and check for values.
fields.each( function( index, el ) {
if ( $( el ).hasClass( 'wpforms-required' ) && $( el ).val().length === 0 ) {
$( el ).addClass( 'wpforms-error' );
$( el ).removeClass( 'wpforms-error' );
location.prepend( '<p class="wpforms-alert-danger wpforms-alert wpforms-alert-required">' + wpforms_builder_providers.required_field + '</p>' );
* Pseudo serializing. Fake it until you make it.