ExoGeniA
ExoGeniA

Reputation: 91

Need to get submission_id of elementor form to add in reference and content of the mail

I use the elementor pro form for my contact form. I want to add the submission_id to the mail. I want to display the id in the reference header and in the body of the mail. Like a ticket-System.

EXP: New Mail from xxx - ID: 4566334

I tried to use the following code to add a new shortcode, that gives back the submission_id, but ist not working. Is empty and dont have a value:

add_shortcode( 'submission_id', 'get_submission_id' );

function get_submission_id() {
  if ( ! isset( $_POST['form_id'] ) || ! isset( $_POST['_wpnonce'] ) ) {
    return '';
  }

  $form_id = intval( $_POST['form_id'] );
  $nonce_value = sanitize_text_field( $_POST['_wpnonce'] );

  if ( ! wp_verify_nonce( $nonce_value, 'elementor-pro-form-' . $form_id ) ) {
    return '';
  }

  $submission_data = ElementorPro\Modules\Forms\Classes\Form::get_instance( $form_id )->get_submission_data();
  if ( ! $submission_data || ! isset( $submission_data['_id'] ) ) {
    return '';
  }

  return $submission_data['_id'];
}

Any other way to add the submission id from elementor form to the mails?

I tried different plugins, but i dont want to pay for a plugin, just to get the id.

Also tried to add my own shortcode the the function.php, but i doesnt give back a value.

UPDATE: It seems that this part doesnt work

if ( ! isset( $_POST['form_id'] ) || ! isset( $_POST['_wpnonce'] ) ) {
    return 'Error 01';
  }

Upvotes: 0

Views: 1231

Answers (1)

Levgo
Levgo

Reputation: 11

My unique id is a code from date and time. I added a hidden text field to the form, then in the advanced tab I selected dynamic data, page, current time. You can set any date/time format along with any character/word etc..

Upvotes: 1

Related Questions