Skip to content

Commit

Permalink
Add - added field for custom pdf filename using field value
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujit Shrestha committed Jul 24, 2024
1 parent 5926332 commit 6d39a60
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
47 changes: 40 additions & 7 deletions includes/abstracts/class-evf-form-fields-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
);

Expand Down
3 changes: 2 additions & 1 deletion includes/fields/class-evf-field-file-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6d39a60

Please sign in to comment.