diff --git a/assets/css/everest-forms.scss b/assets/css/everest-forms.scss index 6c0063911..6b475c224 100644 --- a/assets/css/everest-forms.scss +++ b/assets/css/everest-forms.scss @@ -890,6 +890,89 @@ content: "\f147"; } } + .everest-forms-success-message-popup-bg { + // z-index:98; + background: rgba(0, 0, 0, 0.5); + max-width: 100vw; + height: 100vh; + position: fixed; + width: 100%; + left: 50%; + top: 0; + transform: translate(-50%); + display: flex; + align-items: center; + justify-content: center; + background-size: calc(10 * 2px) calc(10 * 2px); + + .everest-forms-success-message-popup { + z-index: 99999 !important; + height: auto; + gap: 24px; + background: #ffffff; + border-radius: 8px; + width: 386px; + display: flex; + flex-direction: column; + user-select: none; + transition: all ease-in-out .8s; + padding: 20px 20px 54px 20px; + + + .everest-forms-success-message-popup-top{ + color: white; + padding: 13px var(--default-padding); + display: flex; + align-items: center; + justify-content: flex-end; + cursor: default; + user-select: none; + + .everest-forms-success-popup-close-button { + cursor: pointer; + width: 16px; + height: 16px; + padding: 0; + margin: 0; + color: #000000; + } + } + + .everest-forms-success-message-popup-logo { + display: flex; + justify-content: center; + align-items: center; + padding: 0; + } + .everest-forms-success-message-popup-text { + display: flex; + justify-content: center; + flex-direction: column; + width: 346px; + height: 96px; + width: 100%; + max-width: 346px; + height: auto; + gap: 8px; + opacity: 0px; + + .everest-forms-success-message-popup-text-status{ + font-family: Inter; + font-size: 24px; + font-weight: 500; + line-height: 36px; + text-align: center; + } + .everest-forms-success-message-popup-text-message{ + font-family: Inter; + font-size: 15px; + font-weight: 400; + line-height: 26px; + text-align: center; + } + } + } + } .everest-forms-notice--warning { background-color: $orange; diff --git a/assets/images/green-check-success.svg b/assets/images/green-check-success.svg new file mode 100644 index 000000000..96a7e364f --- /dev/null +++ b/assets/images/green-check-success.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/assets/images/popup-close-button.svg b/assets/images/popup-close-button.svg new file mode 100644 index 000000000..446188711 --- /dev/null +++ b/assets/images/popup-close-button.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/js/frontend/ajax-submission.js b/assets/js/frontend/ajax-submission.js index 234c618b0..fd166e895 100644 --- a/assets/js/frontend/ajax-submission.js +++ b/assets/js/frontend/ajax-submission.js @@ -76,7 +76,7 @@ jQuery( function( $ ) { if ( errors.length > 0 ) { $( [document.documentElement, document.body] ).animate({ - scrollTop: errors.last().offset().top + scrollTop: errors.last().offset().top-100 }, 800 ); return; } @@ -117,6 +117,7 @@ jQuery( function( $ ) { let pdf_download_message = ''; let quiz_reporting = ''; let preview_confirmation = ''; + let message_display_location = ''; if(xhr.data.form_id !== undefined && xhr.data.entry_id !== undefined && xhr.data.pdf_download == true){ pdf_download_message = '
' + xhr.data.pdf_download_message + ''; } @@ -128,6 +129,9 @@ jQuery( function( $ ) { preview_confirmation = xhr.data.preview_confirmation; } + if( xhr.data.message_display_location !== undefined ){ + message_display_location = xhr.data.message_display_location; + } var paymentMethod = formTuple.find( ".everest-forms-stripe-gateways-tabs .evf-tab" ).has( 'a.active' ).data( 'gateway' ); @@ -154,9 +158,43 @@ jQuery( function( $ ) { formTuple.trigger( 'evf_process_payment', xhr.data ); return; } + + //Resets the form fields. formTuple.trigger( 'reset' ); - formTuple.closest( '.everest-forms' ).html( '' + quiz_reporting + preview_confirmation ).focus(); - localStorage.removeItem(formTuple.attr('id')); + //Makes the submit button enabled. + btn.attr( 'disabled', false ).html( everest_forms_ajax_submission_params.submit ); + //Removes perviously existing notice. + formTuple.closest( '.everest-forms' ).find( '.everest-forms-notice' ).remove(); + + if( "top" === message_display_location ){ + formTuple.closest( '.everest-forms' ).prepend( '' ).focus(); + formTuple.closest( '.everest-forms' ).append( quiz_reporting + preview_confirmation ); + } + + else if ( "bottom" === message_display_location ){ + formTuple.closest('.everest-forms').append( '' + quiz_reporting + preview_confirmation ).focus(); + } + + else if ( "hide" === message_display_location ) { + formTuple.closest( '.everest-forms' ).html( '' + quiz_reporting + preview_confirmation ).focus(); + } + + else if ( "popup" === message_display_location ) { + formTuple.closest( '.everest-forms' ).prepend( '
X
'+ xhr.data.response.charAt(0).toUpperCase() + xhr.data.response.substr(1) + '!
' + xhr.data.message + '
' ).focus(); + + //Appends quiz reportings and preview below form. + formTuple.closest( '.everest-forms' ).append( quiz_reporting + preview_confirmation ); + + //Removes the message on click of 'x' button. + jQuery( document ).on( 'click' ,"#everest-forms-success-popup-close-button" , + function (){ + formTuple.closest( '.everest-forms' ).find( '.everest-forms-success-message-popup' ).remove(); + formTuple.closest( '.everest-forms' ).find( '.everest-forms-success-message-popup-bg' ).remove(); + } + ); + } + + localStorage.removeItem( formTuple.attr( 'id' ) ) ; // Trigger for form submission success. var event = new CustomEvent("everest_forms_ajax_submission_success", { @@ -257,9 +295,11 @@ jQuery( function( $ ) { }) .always( function( xhr ) { var redirect_url = ( xhr.data && xhr.data.redirect_url ) ? xhr.data.redirect_url : ''; - if ( ! redirect_url && $( '.everest-forms-notice' ).length ) { + + var should_scroll_to_message = ( xhr.data && xhr.data.submission_message_scroll ) ? xhr.data.submission_message_scroll : 1 ; + if ( (! redirect_url && $( '.everest-forms-notice' ).length ) && 1 == should_scroll_to_message) { $( [document.documentElement, document.body] ).animate({ - scrollTop: $( '.everest-forms-notice' ).offset().top + scrollTop: $( '.everest-forms-notice' ).offset().top - 100 }, 800 ); } }); diff --git a/includes/admin/builder/class-evf-builder-settings.php b/includes/admin/builder/class-evf-builder-settings.php index bf2764a6c..d9099b1a9 100644 --- a/includes/admin/builder/class-evf-builder-settings.php +++ b/includes/admin/builder/class-evf-builder-settings.php @@ -608,6 +608,24 @@ public function output_content() { 'tooltip' => sprintf( esc_html__( 'Success message that shows up after submitting form. Learn More', 'everest-forms' ), esc_url( 'https://docs.everestforms.net/docs/general-settings/#4-toc-title' ) ), ) ); + everest_forms_panel_field( + 'select', + 'settings', + 'successful_form_submission_message_display_location', + $this->form_data, + esc_html__( 'Success message display location', 'everest-forms' ), + array( + 'default' => 'hide', + /* translators: %1$s - general settings docs url */ + 'tooltip' => sprintf( esc_html__( 'Choose where to display success message. Learn More', 'everest-forms' ), esc_url( 'https://docs.everestforms.net/docs/confirmations/' ) ), + 'options' => array( + 'hide' => esc_html__( 'Hide form', 'everest-forms' ), + 'top' => esc_html__( 'Top', 'everest-forms' ), + 'bottom' => esc_html__( 'Bottom', 'everest-forms' ), + 'popup' => esc_html__( 'Popup', 'everest-forms' ), + ), + ) + ); everest_forms_panel_field( 'toggle', 'settings', diff --git a/includes/class-evf-form-task.php b/includes/class-evf-form-task.php index 962029aa1..467621841 100644 --- a/includes/class-evf-form-task.php +++ b/includes/class-evf-form-task.php @@ -65,6 +65,9 @@ public function __construct() { add_action( 'everest_forms_complete_entry_save', array( $this, 'evf_set_approval_status' ), 10, 2 ); add_action( 'admin_init', array( $this, 'evf_admin_approve_entry' ), 10, 2 ); add_action( 'admin_init', array( $this, 'evf_admin_deny_entry' ) ); + // add_action( 'everest_forms_after_success_message_display_location', array( $this, 'evf_success_message_display_location' ), 10, 3 ); + add_action( 'everest_forms_before_template_part' , array($this , 'evf_success_message_display_location') , 10, 5); + add_action( 'everest_forms_after_template_part' , array($this , 'evf_success_message_display_location') , 10, 5); } /** @@ -109,7 +112,6 @@ public function listen_task() { if ( ! empty( $this->errors[ $form_id ]['footer'] ) ) { $message .= ' ' . $this->errors[ $form_id ]['footer']; } - wp_send_json( array( 'message' => $message, @@ -136,7 +138,6 @@ public function do_task( $entry ) { $this->ajax_err = array(); $this->evf_notice_print = false; $logger = evf_get_logger(); - // Check nonce for form submission. if ( empty( $_POST[ '_wpnonce' . $form_id ] ) || ! wp_verify_nonce( wp_unslash( sanitize_key( $_POST[ '_wpnonce' . $form_id ] ) ), 'everest-forms_process_submit' ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->errors[ $form_id ]['header'] = esc_html__( 'We were unable to process your form, please try again.', 'everest-forms' ); @@ -174,7 +175,6 @@ public function do_task( $entry ) { // Pre-process/validate hooks and filter. Data is not validated or cleaned yet so use with caution. $entry = apply_filters( 'everest_forms_process_before_filter', $entry, $this->form_data ); $this->form_data['page_id'] = array_key_exists( 'post_id', $entry ) ? $entry['post_id'] : $form_id; - $logger->info( __( 'Everest Forms Process Before.', 'everest-forms' ), array( 'source' => 'form-submission' ) @@ -350,8 +350,8 @@ public function do_task( $entry ) { } } - $recaptcha_verified = true; - break; + $recaptcha_verified = true; + break; } } } @@ -596,10 +596,20 @@ public function do_task( $entry ) { $this->form_data['settings']['redirect_to'] = '0' === $this->form_data['settings']['redirect_to'] ? 'same' : $this->form_data['settings']['redirect_to']; if ( '1' === $ajax_form_submission ) { - $response_data['message'] = $message; - $response_data['response'] = 'success'; - $response_data['form_id'] = $form_id; - $response_data['entry_id'] = $entry_id; + $response_data['message'] = $message; + $response_data['response'] = 'success'; + $response_data['form_id'] = $form_id; + $response_data['entry_id'] = $entry_id; + $response_data['message_display_location'] = isset( $settings['successful_form_submission_message_display_location'] ) && 'null' !== $settings['successful_form_submission_message_display_location'] ? $settings['successful_form_submission_message_display_location'] : 'hide'; + $response_data['submission_message_scroll'] = isset( $settings['submission_message_scroll'] ) && 'null' !== $settings['submission_message_scroll'] ? $this->form_data['settings']['submission_message_scroll'] : '1'; + + // Sending images required for popup. + if ( 'popup' === $response_data['message_display_location'] ) { + $response_data['image_url'] = array( + 'green_check' => plugins_url( 'assets/images/green-check-success.svg', EVF_PLUGIN_FILE ), + 'close_btn' => plugins_url( 'assets/images/popup-close-button.svg', EVF_PLUGIN_FILE ), + ); + } if ( defined( 'EVF_PDF_SUBMISSION_VERSION' ) && ( 'yes' === get_option( 'everest_forms_pdf_download_after_submit', 'no' ) || ( isset( $pdf_submission['everest_forms_pdf_download_after_submit'] ) && 'yes' === $pdf_submission['everest_forms_pdf_download_after_submit'] ) ) ) { $response_data['pdf_download'] = true; @@ -649,7 +659,21 @@ public function do_task( $entry ) { $response_data = apply_filters( 'everest_forms_after_success_ajax_message', $response_data, $this->form_data, $entry ); return $response_data; } elseif ( ( 'same' === $this->form_data['settings']['redirect_to'] && empty( $submission_redirection_process ) ) || ( ! empty( $submission_redirection_process ) && 'same_page' == $submission_redirection_process['redirect_to'] ) ) { - evf_add_notice( $message, 'success' ); + $setting_data['message_display_location'] = isset( $settings['successful_form_submission_message_display_location'] ) && 'null' !== $settings['successful_form_submission_message_display_location'] ? $settings['successful_form_submission_message_display_location'] : 'hide'; + + // error_log(print_r($this->form_data , true)); + // error_log(print_r($this->form_fields , true)); + + // $atts = array( 'id' => 32 ); + // EVF_Shortcode_Form::view( $atts ); + // } + evf_add_notice( $message, 'success' ); + + do_action( 'everest_forms_after_success_message_display_location', $setting_data['message_display_location'], $message, $form_id ); + + // ?> + + // info( 'Everest Forms After success Message.', @@ -699,7 +723,7 @@ public function ajax_process_redirect( $url ) { } /** - * Check the sucessful message. + * Check the successful message. * * @param bool $status Message status. * @param int $form_id Form ID. @@ -1432,4 +1456,122 @@ public function evf_set_approval_status( $entry_id, $form_data ) { update_option( 'everest_forms_admin_entry_approval_token', $evf_new_token ); } } +static $call = 1; + /** + * Display confirmation message in different location as per the option provided in settings. + * + * @param int $display_location where message is displayed. + * @param string $message Confirmation message to display. + */ + public function evf_success_message_display_location( $template_name, $template_path, $located , $args , $where) { + $display_location = $this->form_data['settings']['successful_form_submission_message_display_location'] ; + $settings = $this->form_data['settings']; + $message = isset( $settings['successful_form_submission_message'] ) ? $settings['successful_form_submission_message'] : __( 'Thanks for contacting us! We will be in touch with you shortly.', 'everest-forms' ); + + // error_log( print_r( $form_id, true ) ); + + // $thm = evf()->form->get($form_id); + // error_log( print_r( $thm, true ) ); + + if ( 'hide' === $display_location ) { + evf_add_notice( $message, 'success' ); + } elseif ( 'top' === $display_location ) { + + // error_log(print_r($this->form_data, true)); + + error_log(print_r($this->form_data['form_fields'] , true)); + // error_log(print_r($this->form_data , true)); + + + // do_action('everest_forms_display_field_before' , $this->form_data['form_fields'] , $this->form_data); + // do_action('everest_forms_display_field_after' , $this->form_data['form_fields'] , $this->form_data); + + + // do_action('everest_forms_frontend_output_success' , $this->form_data['form_fields'] , $this->form_data); + + + + // trying method 1: + // error_log(print_r($this->form_data , true)); + // EVF_Shortcode_Form::view( $atts ); + + // 2: + // echo '
'; + // echo '
'; + // do_action('everest_forms_frontend_output' , $this->form_data , 'title1234' , 'description' , []); + // echo ''; + //3 : + // $form_atts = apply_filters( 'everest_forms_frontend_form_atts', $form_atts, $form_data ); + // // Begin to build the output. + // do_action( 'everest_forms_frontend_output_container_before', $form_data, $form ); + + // printf( '
', esc_attr( $classes ), absint( $form_id ) ); + + // do_action( 'everest_forms_frontend_output_form_before', $form_data, $form, $errors ); + // echo '
'; + // if ( evf_is_amp() ) { + // $state = array( + // 'submitting' => false, + // ); + // printf( + // '', + // self::get_form_amp_state_id( $form_id ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + // wp_json_encode( $state ) + // ); + // } + // do_action( 'everest_forms_frontend_output', $form_data, $title, $description, $errors ); + + // echo '
'; + + // 4: + // add_action( + // 'everest_forms_before_template_part', + // function ( $template_name, $template_path, $located, $args , $form_id) { + // // this check makes sure form is rendered for success notice only + if ( 'notices/success.php' === $template_name ) { + + // error_log(print_r($template_name , true)); + // $atts = array( 'id' => 32 , 'title' => "hello"); + + // //6: + // // if(! empty( $form_id ) ){ + // EVF_Shortcode_Form::view( $atts ); + // $this -> listen_task(); + // // } + + // // 5: + // // do_action('everest_forms_frontend_output' , $this->form_data , 'title1234' , 'description' , []); + + + } + // }, + // 10, + // 5 + // ); + + + // 5: + $form_id = isset( $_POST['everest_forms']['id'] ) && ! empty( $_POST['everest_forms']['id'] ) ? absint( $_POST['everest_forms']['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification + error_log(print_r($template_name , true)); + + // error_log(print_r($this->form_data , true)); + error_log(print_r($form_id , true)); + if( 'notices/success.php' === $template_name && 'before_template_part' === $where ){ + // error_log("here now"); + // error_log(print_r($template_name , true)); + + // EVF_Shortcode_Form::output( ['id' => 32] ); + + } + + // EVF_Shortcode_Form::view( $atts ); + + } elseif ( 'bottom' === $display_location ) { + // evf_add_notice( $message, 'success' ); + // do_action('everest_forms_frontend_output' , $this->form_data , 'title1234' , 'description' , []) + + } elseif ( 'popup' === $display_location ) { + // evf_add_notice( $message, 'success' ); + } + } } diff --git a/includes/class-evf-shortcodes.php b/includes/class-evf-shortcodes.php index ae76773c1..698ad5d14 100644 --- a/includes/class-evf-shortcodes.php +++ b/includes/class-evf-shortcodes.php @@ -25,6 +25,7 @@ public static function init() { foreach ( $shortcodes as $shortcode => $function ) { add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function ); + // error_log(print_r($function , true)); } } @@ -64,6 +65,8 @@ public static function shortcode_wrapper( * @return string */ public static function form( $atts ) { + // error_log(print_r($atts , true)); + return self::shortcode_wrapper( array( 'EVF_Shortcode_Form', 'output' ), $atts ); } diff --git a/includes/evf-core-functions.php b/includes/evf-core-functions.php index eada3780e..2bc8ef416 100644 --- a/includes/evf-core-functions.php +++ b/includes/evf-core-functions.php @@ -124,12 +124,18 @@ function evf_get_template( $template_name, $args = array(), $template_path = '', } extract( $args ); // @codingStandardsIgnoreLine } + // error_log(print_r("is core funciton before template? ? " , true)); + $form_id = isset($_POST['everest_forms']['id']) && !empty($_POST['everest_forms']['id']) ? $_POST['everest_forms']['id'] : ''; + // error_log("ereer"); + // error_log( print_r( $form_id, true ) ); + // error_log("pereer"); - do_action( 'everest_forms_before_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] ); + + do_action( 'everest_forms_before_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] , 'before_template_part'); include $action_args['located']; - do_action( 'everest_forms_after_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] ); + do_action( 'everest_forms_after_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] , 'after_template_part'); } /** diff --git a/includes/shortcodes/class-evf-shortcode-form.php b/includes/shortcodes/class-evf-shortcode-form.php index aa454e199..9abd52696 100644 --- a/includes/shortcodes/class-evf-shortcode-form.php +++ b/includes/shortcodes/class-evf-shortcode-form.php @@ -833,6 +833,9 @@ public static function get_field_properties( $field, $form_data, $attributes = a * @param array $atts Attributes. */ public static function output( $atts ) { + // error_log("here in EVF_shortcode_form output functoin"); + // error_log(print_r($atts , true)); + wp_enqueue_script( 'everest-forms' ); wp_enqueue_script( 'everest-forms-survey-polls-quiz-script' ); @@ -875,7 +878,8 @@ public static function output( $atts ) { * * @param array $atts Attributes. */ - private static function view( $atts ) { + public static function view( $atts ) { + echo "here"; $id = isset( $atts['id'] ) ? $atts['id'] : false; $title = isset( $atts['title'] ) ? $atts['title'] : false; $description = isset( $atts['description'] ) ? $atts['description'] : false; @@ -1147,6 +1151,7 @@ private static function view( $atts ) { if ( is_super_admin() ) { evf_debug_data( $form_data ); } + echo "there"; } /**