PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmFormsController.php +97 -168 6.5.36.7 View file →
@@ -282,9 +282,10 @@
282 282 $url = admin_url( 'admin.php?page=formidable' );
283 283 $message = 'form_duplicate_error';
284 284
285 285 if ( $form ) {
286 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
286 + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : '';
287 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template );
287 288 $message = 'form_duplicated';
288 289 }
289 290
290 291 $url .= '&message=' . $message;
@@ -696,9 +697,9 @@
696 697 self::create_default_on_submit_action( $form_id );
697 698 self::create_default_email_action( $form_id );
698 699
699 700 $response = array(
700 - 'redirect' => FrmForm::get_edit_link( $form_id ),
701 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
701 702 );
702 703
703 704 echo wp_json_encode( $response );
704 705 wp_die();
@@ -704,46 +705,13 @@
704 705 wp_die();
705 706 }
706 707
707 708 /**
708 - * Create a custom template from a form
709 - *
710 - * @since 3.06
711 - */
712 - public static function build_template() {
713 - global $wpdb;
714 -
715 - FrmAppHelper::permission_check( 'frm_edit_forms' );
716 - check_ajax_referer( 'frm_ajax', 'nonce' );
717 -
718 - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
719 - $new_form_id = FrmForm::duplicate( $form_id, 1, true );
720 - if ( ! $new_form_id ) {
721 - $response = array(
722 - 'message' => __( 'There was an error creating a template.', 'formidable' ),
723 - );
724 - } else {
725 - $new_values = self::get_modal_values();
726 - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
727 - if ( $query_results ) {
728 - FrmForm::clear_form_cache();
729 - }
730 -
731 - $response = array(
732 - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
733 - );
734 - }
735 -
736 - echo wp_json_encode( $response );
737 - wp_die();
738 - }
739 -
740 - /**
741 709 * Before creating a new form, get the name and description from the modal.
742 710 *
743 711 * @since 4.0
744 712 */
745 - private static function get_modal_values() {
713 + public static function get_modal_values() {
746 714 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
747 715 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
748 716
749 717 return array(
@@ -966,147 +934,43 @@
966 934
967 935 return $save;
968 936 }
969 937
970 - /**
971 - * @return bool
972 - */
973 - public static function expired() {
974 - global $frm_expired;
975 - return $frm_expired;
976 - }
938 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
939 + global $frm_vars;
977 940
978 - /**
979 - * Get data from api before rendering it so that we can flag the modal as expired
980 - *
981 - * @return void
982 - */
983 - public static function before_list_templates() {
984 - global $frm_templates;
985 - global $frm_expired;
986 - global $frm_license_type;
987 -
988 - $api = new FrmFormTemplateApi();
989 - $frm_templates = $api->get_api_info();
990 - $expired = false;
991 - $license_type = '';
992 - if ( isset( $frm_templates['error'] ) ) {
993 - $error = $frm_templates['error']['message'];
994 - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
995 - $expired = 'expired' === $frm_templates['error']['code'];
996 - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : '';
997 - unset( $frm_templates['error'] );
998 - }
999 -
1000 - $frm_expired = $expired;
1001 - $frm_license_type = $license_type;
1002 - }
1003 -
1004 - /**
1005 - * @return void
1006 - */
1007 - public static function list_templates() {
1008 - global $frm_templates;
1009 - global $frm_license_type;
1010 -
1011 - $templates = $frm_templates;
1012 - $custom_templates = array();
1013 - $templates_by_category = array();
1014 -
1015 - self::add_user_templates( $custom_templates );
1016 -
1017 - foreach ( $templates as $template ) {
1018 - if ( ! isset( $template['categories'] ) ) {
1019 - continue;
1020 - }
1021 -
1022 - foreach ( $template['categories'] as $category ) {
1023 - if ( ! isset( $templates_by_category[ $category ] ) ) {
1024 - $templates_by_category[ $category ] = array();
1025 - }
1026 -
1027 - $templates_by_category[ $category ][] = $template;
1028 - }
1029 - }
1030 - unset( $template );
1031 -
1032 - // Subcategories that are included elsewhere.
1033 - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' );
1034 -
1035 - $categories = array_keys( $templates_by_category );
1036 - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() );
1037 - $categories = array_diff( $categories, $redundant_cats );
1038 - sort( $categories );
1039 -
1040 - array_walk(
1041 - $custom_templates,
1042 - function( &$template ) {
1043 - $template['custom'] = true;
1044 - }
941 + $form = FrmForm::getOne( $id );
942 + $error_args = array(
943 + 'title' => __( 'You can\'t edit the form', 'formidable' ),
944 + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
945 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
946 + 'continue_url' => add_query_arg(
947 + array(
948 + 'page' => 'formidable',
949 + )
950 + ),
1045 951 );
1046 -
1047 - $my_templates_translation = __( 'My Templates', 'formidable' );
1048 - $categories = array_merge( array( $my_templates_translation ), $categories );
1049 - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
1050 - $license_type = $frm_license_type;
1051 - $args = compact( 'pricing', 'license_type' );
1052 - $where = apply_filters( 'frm_forms_dropdown', array(), '' );
1053 - $forms = FrmForm::get_published_forms( $where );
1054 - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/';
1055 -
1056 - $templates_by_category[ $my_templates_translation ] = $custom_templates;
1057 -
1058 - unset( $pricing, $license_type, $where );
1059 - wp_enqueue_script( 'accordion' ); // register accordion for template groups
1060 - require $view_path . 'list-templates.php';
1061 - }
1062 -
1063 - /**
1064 - * @since 4.03.01
1065 - */
1066 - private static function get_template_categories( $templates ) {
1067 - $categories = array();
1068 - foreach ( $templates as $template ) {
1069 - if ( isset( $template['categories'] ) ) {
1070 - $categories = array_merge( $categories, $template['categories'] );
1071 - }
952 + if ( ! $form ) {
953 + FrmAppController::show_error_modal( $error_args );
954 + return;
1072 955 }
1073 - $exclude_cats = FrmFormsHelper::ignore_template_categories();
1074 - $categories = array_unique( $categories );
1075 - $categories = array_diff( $categories, $exclude_cats );
1076 - sort( $categories );
1077 - return $categories;
1078 - }
1079 956
1080 - private static function add_user_templates( &$templates ) {
1081 - $user_templates = array(
1082 - 'is_template' => 1,
1083 - 'default_template' => 0,
1084 - );
1085 - $user_templates = FrmForm::getAll( $user_templates, 'name' );
1086 - foreach ( $user_templates as $template ) {
1087 - $template = array(
1088 - 'id' => $template->id,
1089 - 'name' => $template->name,
1090 - 'key' => $template->form_key,
1091 - 'description' => $template->description,
1092 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ),
1093 - 'released' => $template->created_at,
1094 - 'installed' => 1,
957 + if ( 'trash' === $form->status ) {
958 + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
959 + $error_args['continue_url'] = add_query_arg(
960 + array(
961 + 'page' => 'formidable',
962 + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
963 + 'form_type' => 'trash',
964 + 'frm_action' => 'untrash',
965 + 'id' => $id,
966 + )
1095 967 );
1096 - array_unshift( $templates, $template );
1097 - unset( $template );
968 + $error_args['continue_text'] = __( 'Restore form', 'formidable' );
969 + FrmAppController::show_error_modal( $error_args );
970 + return;
1098 971 }
1099 - }
1100 972
1101 - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1102 - global $frm_vars;
1103 -
1104 - $form = FrmForm::getOne( $id );
1105 - if ( ! $form ) {
1106 - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
1107 - }
1108 -
1109 973 if ( $form->parent_form_id ) {
1110 974 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1111 975 wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) );
1112 976 }
@@ -1820,8 +1684,33 @@
1820 1684 return;
1821 1685 }
1822 1686 }
1823 1687
1688 + /**
1689 + * Rename a form.
1690 + *
1691 + * Handles the AJAX request for renaming a form.
1692 + *
1693 + * @since 6.7
1694 + *
1695 + * @return void
1696 + */
1697 + public static function rename_form() {
1698 + // Check permission and nonce
1699 + FrmAppHelper::permission_check( 'frm_edit_forms' );
1700 + check_ajax_referer( 'frm_ajax', 'nonce' );
1701 +
1702 + // Get posted data
1703 + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
1704 + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
1705 +
1706 + // Update the form name and form key.
1707 + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
1708 + FrmForm::update( $form_id, compact( 'name', 'form_key' ) );
1709 +
1710 + wp_send_json_success( compact( 'form_key' ) );
1711 + }
1712 +
1824 1713 public static function json_error( $errors ) {
1825 1714 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1826 1715
1827 1716 return $errors;
@@ -3150,6 +3039,46 @@
3150 3039 * @since 3.06
3151 3040 */
3152 3041 public static function add_new() {
3153 3042 _deprecated_function( __FUNCTION__, '4.08' );
3043 + }
3044 +
3045 + /**
3046 + * Create a custom template from a form
3047 + *
3048 + * @since 3.06
3049 + * @deprecated x.x
3050 + */
3051 + public static function build_template() {
3052 + _deprecated_function( __METHOD__, 'x.x' );
3053 + }
3054 +
3055 + /**
3056 + * @deprecated x.x
3057 + *
3058 + * @return bool
3059 + */
3060 + public static function expired() {
3061 + _deprecated_function( __METHOD__, 'x.x' );
3062 + return FrmAddonsController::is_license_expired();
3063 + }
3064 +
3065 + /**
3066 + * Get data from api before rendering it so that we can flag the modal as expired
3067 + *
3068 + * @deprecated x.x
3069 + *
3070 + * @return void
3071 + */
3072 + public static function before_list_templates() {
3073 + _deprecated_function( __METHOD__, 'x.x' );
3074 + }
3075 +
3076 + /**
3077 + * @deprecated x.x
3078 + *
3079 + * @return void
3080 + */
3081 + public static function list_templates() {
3082 + _deprecated_function( __METHOD__, 'x.x' );
3154 3083 }
3155 3084 }