Saving an FF-generated PDF to the server

Est. Reading: 1 minute
By: Rob LeVine
Created: 07/02/2024
Category:
Difficulty: Intermediate

Saving an FF-generated PDF to the server

While the Formidable Forms PDF addon is a huge timesaver, it's also very frustrating in that there's no way to force it to save the PDF to the server as it's generated each time the user clicks the download link. Here's a workaround (semi-hack) for saving a PDF to the server during its generation via an email notification.

	add_filter('frm_pdfs_download_url', 'savePDFToServer', 10, 2);
	function savePDFToServer( $url, $args ) {
		$file_download = curl_init();
		curl_setopt($file_download, CURLOPT_URL, $url);
		curl_setopt($file_download, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($file_download, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($file_download, CURLOPT_AUTOREFERER, true);
		$cookie = $_SERVER["HTTP_COOKIE"];
		curl_setopt($file_download, CURLOPT_COOKIE, $cookie);

		$itemID = $args['shortcode_atts']['id'];
		$fileName = "file-$itemID.pdf"; // make the file name whatever you want
		
		$result = curl_exec($file_download);
		$path = ABSPATH . "/documents/" . $fileName;
		file_put_contents($path, $result);
		
		return $url;
	}

Leave a Reply

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crosschevron-leftchevron-rightarrow-right