0

I currently have a form that redirects to an email handler php file. Currently we email the user a pdf when they submit the form, but I'd like to change it to where the pdf just opens in a new tab when submitted. Don't mind the terrible naming conventions. The below code is giving me a WordPress error, and I'm not sure how to get it working properly.

<?php

header('Content-type: application/pdf');

header('Content-Disposition: inline; filename="$_POST["cm-f-djuiyhkr"]');

readfile($_POST['cm-f-djuiyhkr']);

?> 
Kyle White
  • 89
  • 5
  • 1
    Please post the error – Chris Haas Nov 19 '21 at 17:35
  • The only error I see is "there has been a critical error on your website" – Kyle White Nov 19 '21 at 17:57
  • Please enable [debugging for WordPress](https://wordpress.org/support/article/debugging-in-wordpress/) and [error reporting for PHP](https://stackoverflow.com/a/21429652/231316) – Chris Haas Nov 19 '21 at 17:59
  • It looks like the PHP is fine from what I can see, but when it tries to open the pdf is says "Failed to load PDF document.". Also, it is opening in the same tab. How can I have it open in a new tab? Thanks – Kyle White Nov 19 '21 at 19:45
  • The moment you hit PHP, you are stuck to the same window/tab as the request, This is just how HTTP works. To open a new window/tab, you need to initiate that on the client side. If you have a form or a link, you can do that with the [`target`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-target) attribute. – Chris Haas Nov 19 '21 at 19:56

0 Answers0