This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
Use this hook to filter the PDF entry export file name.
Usage
add_filter('frm_pdfs_export_file_name', 'prepend_site_name' , 10, 2);
Parameters
- $file_name (string): The file name.
- $args (array): This contains shortcode attributes and the following values.
- entry (object): The entry object.
- form (object): The form object. This doesn't always exist.
- form_name (string): The name of form. This doesn't always exist.
Examples
Prepend site name to filename
add_filter('frm_pdfs_export_file_name', 'prepend_site_name' , 10, 2);
function prepend_site_name( $file_name, $args ) {
$file_name = sanitize_title( get_bloginfo( 'name' ) ) . '-' . $file_name;
return $file_name;
}
Prepend field value to filename
Use this code example to prepend the generated PDF file name with a value from the entry. (i.e. name of the user that created the entry)
add_filter('frm_pdfs_export_file_name', 'prepend_field_value' , 10, 2);
function prepend_field_value( $file_name, $args ) {
$entry_id=$args['entry']->id;
$fieldvalue=FrmProEntriesController::get_field_value_shortcode(array('field_id' => 2, 'entry' => $entry_id)); //change 2 to the ID of the field where the unique value is stored in your form
$file_name = $fieldvalue. '-' . $file_name;
return $file_name;
}
Customize downloaded PDF filename to match post title
Use this code example to change all PDFs downloaded for the form to match their associated post title made from a Post action. Replace 23 with your form ID.
add_filter('frm_pdfs_export_file_name', 'use_post_title_for_pdf_filename' , 10, 2);
function use_post_title_for_pdf_filename( $file_name, $args ) {
$target_form_id = 23; //Change 23 to the ID of the form.
if ( $target_form_id !== (int) $args['entry']->form_id ) {
return $file_name;
}
$post_id = $args['entry']->post_id;
if ( ! $post_id ) {
return $file_name;
}
$post = get_post( $post_id );
if ( ! $post || ! $post->post_title ) {
return $file_name;
}
return $post->post_title;
}