'Get page permalink in contact form

Hope someone can help me.

function leverage_handle_ajax_request() {

    if ( ! empty( $_POST ) ) {

        require_once( plugin_dir_path( __FILE__ ) . 'recaptcha.php' );

        if ( isset( $_POST['section'] ) && $_POST['section'] == 'leverage_form' ) {
            $source             = 'Contact Form';
            $field_send_options = 'form_sending_options';
            $field_recipient    = 'form_email_recipient';
            $field_webhook_url  = 'form_webhook_url';
            $wpnonce            = 'leverage_form_wpnonce';

            $subject_text    = get_field( 'form_subject_message', 'option' );
            $heading_text    = get_field( 'form_heading_message', 'option' );
            $success_text    = get_field( 'form_success_message', 'option' );
            $validation_text = get_field( 'form_validation_message', 'option' );
            $error_text      = get_field( 'form_error_message', 'option' );

        } elseif ( isset( $_POST['section'] ) && $_POST['section'] == 'leverage_subscribe' ) {  
            $source             = 'Subscribe Form';                  
            $field_send_options = 'subscribe_sending_options';
            $field_recipient    = 'subscribe_email_recipient';
            $field_webhook_url  = 'subscribe_webhook_url';
            $wpnonce            = 'leverage_subscribe_wpnonce';

            $subject_text    = get_field( 'subscribe_subject_message', 'option' );
            $heading_text    = get_field( 'subscribe_heading_message', 'option' );
            $success_text    = get_field( 'subscribe_success_message', 'option' );
            $validation_text = get_field( 'subscribe_validation_message', 'option' );
            $error_text      = get_field( 'subscribe_error_message', 'option' );
        }

        if ( get_field( $field_recipient, 'option' ) ) {
            $recipient = get_field( $field_recipient, 'option' );
        } else {
            $recipient = get_option( 'admin_email' );
        }
    
        if( isset( $_POST['email'] ) ) {
            $from = sanitize_email( $_POST['email'] );
        } else {
            $from = null;
        }

        if( isset( $_POST['step'] ) ) {
            $step = $_POST['step'];
        } else {
            $step = 'send';
        }

        $to = $recipient;
        
        if ( $subject_text ) {
            $subject = leverage_translate( $subject_text );
        } else {
            $subject = __( 'New contact in ', 'leverage-extra' ) . get_bloginfo( 'name' );
        }

        if ( $heading_text ) {
            $heading_message = leverage_translate( $heading_text );
        } else {
            $heading_message = __( 'New contact in ', 'leverage-extra' ) . get_permalink( $post, $leavename );
        }

        if ( $success_text ) {
            $success_message = leverage_translate( $success_text );
        } else {
            $success_message = __( 'Your message was sent successful. Thanks.', 'leverage-extra' );
        }

        if ( $validation_text ) {
            $validation_message = leverage_translate( $validation_text );
        } else {
            $validation_message = __( 'Validation errors occurred. Please confirm the fields and submit it again.', 'leverage-extra' );
        }

        if ( $error_text ) {
            $error_message = leverage_translate( $error_text );
        } else {
            $error_message =  __( 'Sorry. We were unable to send your message.', 'leverage-extra' );
        }

        $enable_recaptcha = get_field( 'recaptcha', 'option' );

        if ( isset( $enable_recaptcha ) && $enable_recaptcha['enable_recaptcha'] ) {

            if ( ! empty( $reCAPTCHA['success'] ) ) {
                $errCaptcha = '';

            } else {
                $errCaptcha = true;
            }
         
        } else {
            $errCaptcha = '';            
        }
    
        $errFields = array();

        foreach( $_POST as $key => $value ) {
            if ( $key != 'action' && $key != 'section' && $key != 'reCAPTCHA' ) {

                if ( $key == 'email' ) {
                    $validation = filter_var( $_POST[$key], FILTER_VALIDATE_EMAIL );
                } else {                
                    if ( strpos( $key, '*not' ) !== false ) {
                        $validation = true;
                    } else {
                        $validation = ! empty( $_POST[$key] );
                    }
                }
                
                if ( ! $validation ) {
                    $errFields[$key] = true;
                } 
            }
        }

I put thie .get_the_title($post) after $heading_text but nothing happend, anything wrong ?

I've try lots of code(get_permalink( $post = 0, $leavename = false ) but nothing work.

It's about the notice mail(to admin) after user fill the contact form on frontend. I'd like to know which page excatly the user is viewing so that I could increase more budget to the GoogleAd. but I can't find a way to make it happen.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source