I’m using the gform_after_submission() action hook to generate a PDF based on some of the form data, and then making it available to the user to download, using the following code:
$file = 'return_label.pdf';
file_put_contents($file, $pdf_data);
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
}
The problem with rewriting the headers is that the form never fully completes, as in, the form fields stay on the page and the user doesn’t get the confirmation text - so not a great UX. Is there some other function/action that runs after the form fully submits that I can tap into? Or other ideas on how to handle this?