Skip to content

Instantly share code, notes, and snippets.

@danieliser
Last active December 3, 2020 06:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieliser/0060112b18b6013f2683653236b02439 to your computer and use it in GitHub Desktop.
Save danieliser/0060112b18b6013f2683653236b02439 to your computer and use it in GitHub Desktop.
Add support for non integrated form plugins inside Popup Maker. Methods for AJAX & Non-AJAX forms available.
/**
* If your forms process submissions via ajax/javascript this is the method you will need to use.
*
* The following function will handle everything on the Popup Maker side.
* You just need to get your form plugin to call this function when succesffully submitted with the popup ID field.
*
* Example usages. Read below to learn how to complete the full solution for your form plugin.
*
* Mileage will vary as every form & plugin does this in a different way.
* You will need to find out how to do something on successful submission.
*
* Things to consider googling for that should provdide the other half the solution you need.
* - track google analytics even on {insert your form plugin name here} success
* - redirect to thank you page after {insert your form plugin name here} submission
*
* Once you find out how to do something when your form is submitted successfully.
*
* Generally it will look something like this.
*/
jQuery('form.plugin-name').on('success', function () {
var $form = $(this);
// Do something after success here.
});
/**
* Once you have that simply set it up like so.
*/
jQuery('form.plugin-name').on('success', function () {
var $form = $(this);
/**
* Call the Popup Maker forms.success helper function
* which does various things including setting cookies,
* closing the popup etc.
*/
PUM.forms.success($form, {
openpopup: false,
openpopup_id: 0,
closepopup: false,
closedelay: 0,
cookie: {
expires: '+1 year'
}
});
});
<?php
/**
* If your forms process submissions via refresh this is the method you will need to use.
*
* The following function will handle everything on the Popup Maker side.
* You just need to get your form plugin to call this function when succesffully submitted with the popup ID field.
*
* Example usages. Read below to learn how to complete the full solution for your form plugin.
*
* Mileage will vary as every form & plugin does this in a different way.
* You will need to find out how to do something on successful submission.
*
* Things to consider googling for that should provdide the other half the solution you need.
* - do something on {insert your form plugin name here} success
* - redirect to thank you page after {insert your form plugin name here} submission
*
* Once you find out how to do something when your form is submitted successfully.
*
* Generally it will look something like this.
*/
function _custom_form_submission_action( $form, $values ) {
// Do something here.
}
add_action( 'form_plugin_successful_submission', '_custom_form_submission_action', 10, 2 );
/**
* Once you have that simply set it up like so.
*/
function _custom_form_submission_action_for_popup( $form, $values ) {
// Checks for hidden popup field that we add to every form inside a popup.
$popup_id = isset( $_REQUEST['pum_form_popup_id'] ) && absint( $_REQUEST['pum_form_popup_id'] ) > 0 ? absint( $_REQUEST['pum_form_popup_id'] ) : false;
if ( $popup_id ) {
// Call the Popup Maker function to trigger a form submission success on the front end.
// Customize the second parameter to your needs. Defaults shown below can be removed if not used.
pum_trigger_popup_form_success( $popup_id, array(
'cookie' => array(
'expires' => '+1 year',
),
'openpopup' => false,
'openpopup_id' => 0,
'closepopup' => false,
'closedelay' => 0,
) );
}
}
add_action( 'form_plugin_successful_submission', '_custom_form_submission_action_for_popup', 10, 2 );
@devmanb
Copy link

devmanb commented Dec 3, 2020

Thks because i have spend many time for to find this Methode for Ajax success. Good plugin WP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment