From 6d39a60d050d2119daa804ec948cc60dca3143eb Mon Sep 17 00:00:00 2001 From: Sujit Shrestha Date: Wed, 24 Jul 2024 16:02:46 +0545 Subject: [PATCH] Add - added field for custom pdf filename using field value --- .../class-evf-form-fields-upload.php | 47 ++++++++++++++++--- .../fields/class-evf-field-file-upload.php | 3 +- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/includes/abstracts/class-evf-form-fields-upload.php b/includes/abstracts/class-evf-form-fields-upload.php index e30fd28d9..b096f6a0f 100644 --- a/includes/abstracts/class-evf-form-fields-upload.php +++ b/includes/abstracts/class-evf-form-fields-upload.php @@ -515,17 +515,17 @@ public function upload_message( $field ) { } /** - * Get the custom file name + * Get the custom user defined file name * * @param array $field Field data. */ - public function file_name( $field ) { + public function custom_file_name( $field ) { $lbl = $this->field_element( 'label', $field, array( - 'slug' => 'file_name', - 'value' => esc_html__( 'Name of the file', 'everest-forms' ), + 'slug' => 'custom_file_name', + 'value' => esc_html__( 'File name', 'everest-forms' ), 'tooltip' => esc_html__( 'Enter text to be displayed as file name.', 'everest-forms' ), ), false @@ -534,13 +534,46 @@ public function file_name( $field ) { 'text', $field, array( - 'slug' => 'file_name', - 'value' => ! empty( $field['file_name'] ) ? $field['file_name'] : esc_html( 'CustomFileName', 'everest-forms' ), + 'slug' => 'custom_file_name', + 'value' => ! empty( $field['custom_file_name'] ) ? $field['custom_file_name'] : esc_html( 'mycustompdffile', 'everest-forms' ), ), false ); $args = array( - 'slug' => 'file_name', + 'slug' => 'custom_file_name', + 'content' => $lbl . $fld, + ); + + $this->field_element( 'row', $field, $args ); + } + + /** + * Creates file name by using fields of the pdf file + * + * @param array $field Field data. + */ + public function custom_tag_file_name( $field ) { + $lbl = $this->field_element( + 'label', + $field, + array( + 'slug' => 'custom_tag_file_name', + 'value' => esc_html__( 'File name based on field tags', 'everest-forms' ), + 'tooltip' => esc_html__( 'Enter the tags which represents the fields of the form and uses the field value as file name.', 'everest-forms' ), + ) + ); + + $fld = $this->field_element( + 'text', + $field, + array( + 'slug' => 'custom_tag_file_name', + 'value' => ! empty( $field['custom_tag_file_name'] ) ? $field['custom_tag_file_name'] : '', // probably need to put the first tag present + ) + ); + + $args = array( + 'slug' => 'custom_tag_file_name', 'content' => $lbl . $fld, ); diff --git a/includes/fields/class-evf-field-file-upload.php b/includes/fields/class-evf-field-file-upload.php index 08d7d1ba8..f017e1754 100644 --- a/includes/fields/class-evf-field-file-upload.php +++ b/includes/fields/class-evf-field-file-upload.php @@ -30,7 +30,8 @@ public function __construct() { 'description', 'upload_message', 'limit_message', - 'file_name', + 'custom_file_name', //user provided file name + 'custom_tag_file_name', //file name with field tags 'extensions', 'max_size', 'max_file_number',