Trigger shortcode after submit button pressed

I need to execute a shortcode after the user will press the submit button. I am using Contact form 7 and have inserted the form by a shortcode in the Post edit section.

It’s basically a form collecting data and after submit, I will redirect the user to PayPal in a new window. The shortcode for the PayPal button works already on it’s own.

I have tried this function but the form seems to get stuck, I get the loading icon forever, the message is delivered but most important, it’s not executing my shortcode. Not even a simple echo "test";.

add_action ('wpcf7_mail_sent', 'after_mail_sent');
function after_mail_sent () {
  echo do_shortcode ('[book]');

Any ideas please?

Solutions Collecting From Web of "Trigger shortcode after submit button pressed"