| 1 |
<?php |
| 2 |
/** |
| 3 |
* On Submit form action |
| 4 |
* |
| 5 |
* @package Formidable |
| 6 |
* @since 6.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
die( 'You are not allowed to call this page directly.' ); |
| 11 |
} |
| 12 |
|
| 13 |
class FrmOnSubmitAction extends FrmFormAction { |
| 14 |
|
| 15 |
public static $slug = 'on_submit'; |
| 16 |
|
| 17 |
public function __construct() { |
| 18 |
$action_ops = array( |
| 19 |
'classes' => 'frm_icon_font frm_checkmark_icon', |
| 20 |
'active' => true, |
| 21 |
'event' => array( 'create' ), |
| 22 |
'limit' => 99, |
| 23 |
'priority' => 9, |
| 24 |
'color' => 'rgb(66, 193, 178)', |
| 25 |
'keywords' => __( 'redirect, success, confirmation, submit', 'formidable' ), |
| 26 |
); |
| 27 |
$action_ops = apply_filters( 'frm_' . self::$slug . '_control_settings', $action_ops ); |
| 28 |
|
| 29 |
$this->maybe_save_edit_trigger( $action_ops ); |
| 30 |
|
| 31 |
parent::__construct( self::$slug, self::get_name(), $action_ops ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
public static function get_name() { |
| 38 |
return __( 'Confirmation', 'formidable' ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* @return void |
| 43 |
*/ |
| 44 |
public function form( $instance, $args = array() ) { |
| 45 |
include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/on_submit_settings.php'; |
| 46 |
} |
| 47 |
|
| 48 |
public function get_defaults() { |
| 49 |
return array( |
| 50 |
'success_action' => FrmOnSubmitHelper::get_default_action_type(), |
| 51 |
'success_msg' => FrmOnSubmitHelper::get_default_msg(), |
| 52 |
'show_form' => '', |
| 53 |
'success_url' => '', |
| 54 |
'success_page_id' => '', |
| 55 |
'open_in_new_tab' => '', |
| 56 |
'redirect_delay' => '', |
| 57 |
// Value in second. |
| 58 |
'redirect_delay_time' => 8, |
| 59 |
'redirect_delay_msg' => FrmOnSubmitHelper::get_default_redirect_msg(), |
| 60 |
); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* This function should check that $new_instance is set correctly. |
| 65 |
* The newly calculated value of $instance should be returned. |
| 66 |
* If "false" is returned, the instance won't be saved/updated. |
| 67 |
* |
| 68 |
* @param array $new_instance New settings for this instance as input by the user via form(). |
| 69 |
* @param array $old_instance Old settings for this instance. |
| 70 |
* |
| 71 |
* @return array Settings to save or bool false to cancel saving |
| 72 |
*/ |
| 73 |
public function update( $new_instance, $old_instance ) { |
| 74 |
if ( 'redirect' === $new_instance['post_content']['success_action'] && ! empty( $new_instance['post_content']['success_url'] ) ) { |
| 75 |
$new_instance['post_content']['success_url'] = FrmFormsHelper::maybe_add_sanitize_url_attr( |
| 76 |
$new_instance['post_content']['success_url'], |
| 77 |
(int) $new_instance['menu_order'] |
| 78 |
); |
| 79 |
} |
| 80 |
return $new_instance; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Add a workaround in case Pro hasn't been updated. We don't want to |
| 85 |
* lose the trigger and have edit messages start showing on create. |
| 86 |
* |
| 87 |
* @param array $action_ops The action setup details. |
| 88 |
* |
| 89 |
* @return void |
| 90 |
*/ |
| 91 |
protected function maybe_save_edit_trigger( &$action_ops ) { |
| 92 |
if ( $action_ops['event'] === array( 'create' ) && FrmAppHelper::pro_is_installed() ) { |
| 93 |
$action_ops['event'][] = 'update'; |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|