Advertisement
adczk

Forminator - add redirector

Sep 11th, 2023
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'plugins_loaded', 'wpmudev_forminator_add_redirect_url_to_hidden_field_func', 100 );
  4.  
  5. function wpmudev_forminator_add_redirect_url_to_hidden_field_func() {
  6.     if ( defined('FORMINATOR_PRO') && class_exists( 'Forminator' ) ) {
  7.         class wpmudev_forminator_add_redirect_url_to_hidden_field_func{
  8.             private $form_id = 6;//enter form_id here
  9.             private $redirect_url;
  10.  
  11.             public function __construct() {
  12.                 add_filter( 'forminator_form_submit_response', array( $this, 'get_redirect_url_form_submission' ), 20, 2 );
  13.                 add_filter( 'forminator_form_ajax_submit_response', array( $this, 'get_redirect_url_form_submission'), 20, 2 );
  14.                 add_action( 'forminator_form_after_handle_submit', array( $this, 'add_redirect_url_to_hidden_field'), 10, 2);
  15.                 add_action( 'forminator_form_after_save_entry', array( $this, 'add_redirect_url_to_hidden_field'), 10, 2);
  16.             }
  17.  
  18.             public function get_redirect_url_form_submission( $response, $form_id ) {
  19.                 if ( $this->form_id == $form_id ) {
  20.                     if ( ! empty( $response['url'] ) ) {
  21.                         $this->redirect_url = $response['url'];
  22.                     }
  23.                 }
  24.  
  25.                 return $response;
  26.             }
  27.  
  28.             public function add_redirect_url_to_hidden_field( $form_id, $response ) {
  29.                 if ( $this->form_id == $form_id ) {
  30.                     $entry_meta = array(
  31.                         array(
  32.                         'name' => 'hidden-1',
  33.                         'value' => $this->redirect_url
  34.                         )
  35.                     );
  36.                     $entries = Forminator_API::get_entries( $form_id );
  37.                     Forminator_API::update_form_entry( $form_id, $entries[0]->entry_id, $entry_meta );
  38.                 }
  39.             }
  40.  
  41.         }
  42.  
  43.         $run = new wpmudev_forminator_add_redirect_url_to_hidden_field_func;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement