Skip to content

Commit

Permalink
Fixed Custom Post Fields acting as File Uploads on Entry Edit Page (#…
Browse files Browse the repository at this point in the history
…1971)

This PR Closes #1317 

The type checking for upload fields excluded custom fields by default by
not using `get_input_type()`. That already provides the right type for
the custom post fields.

And because files are not provides by an input field during updating a
different field, I skip the `get_value_save_entry()` method, as it has
no value, and removes the image completely.
  • Loading branch information
zackkatz authored Jan 22, 2024
2 parents 64c7d41 + d08020c commit f9b21d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 12 additions & 7 deletions includes/extensions/edit-entry/class-edit-entry-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ private function process_save_process_files( $form_id ) {
*/
public function save_field_value( $value = '', $entry = array(), $field = null, $form = array(), $input_id = '' ) {

if ( ! $field || 'fileupload' != $field->type ) {
if ( ! $field || $field->get_input_type() !== 'fileupload' ) {
return $value;
}

Expand Down Expand Up @@ -915,13 +915,17 @@ private function maybe_update_post_fields( $form ) {
case 'post_category':
break;
case 'post_custom_field':
if ( is_array( $value ) && ( floatval( $field_id ) !== floatval( $field->id ) ) ) {
if ( $field->get_input_type() === 'fileupload' ) {
break;
}

if ( is_array( $value ) && ( (float) $field_id !== (float) $field->id ) ) {
$value = $value[ $field_id ];
}

if ( ! empty( $field->customFieldTemplateEnabled ) ) {
$value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
}
if( ! empty( $field->customFieldTemplateEnabled ) ) {
$value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
}

$value = $field->get_value_save_entry( $value, $form, '', $this->entry['id'], $this->entry );

Expand Down Expand Up @@ -1509,8 +1513,9 @@ public function modify_edit_field_input( $field_content = '', $field = null, $va

// If the form has been submitted, then we don't need to pre-fill the values,
// Except for fileupload type and when a field input is overridden- run always!!
if (
( $this->is_edit_entry_submission() && ! in_array( $field->type, array( 'fileupload', 'post_image' ) ) )

if(
( $this->is_edit_entry_submission() && !in_array( $field->get_input_type(), array( 'fileupload', 'post_image' ) ) )
&& false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
&& ! GFCommon::is_product_field( $field->type )
|| ! empty( $field_content )
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This release makes it easier to customize search results per-View instead of glo
* Added: Ability to send notifications using Gravity Forms when an entry is deleted by selecting the "GravityView - Entry is deleted" event from the event dropdown in Gravity Forms notifications settings
* Fixed: Sorting the View by entry ID in ascending and descending order would yield the same result
* Fixed: Survey fields without a rating would show a 1-star rating
* Fixed: Custom Post Field acting as File Uploads can now be edited on the Edit Entry page

__Developer Updates:__

Expand Down

0 comments on commit f9b21d0

Please sign in to comment.