Open rafaehlers opened 1 month ago
@omarkasem, please work on this.
@rafaehlers Please share any related snippets.
Not exactly related, but deal with files uploaded on the edit entry page:
add_filter( 'gform_validation_30', 'custom_validation_filename', 11 ); // Change 30 to your form ID
function custom_validation_filename( $validation_result ) {
$form = $validation_result['form'];
$uploaded_files = [];
// Multi-file upload field.
if ( ! empty( $_POST['gform_uploaded_files'] ) ) {
$uploaded_files = json_decode( stripslashes( $_POST['gform_uploaded_files'] ), true );
}
// Single file upload field.
if ( ! empty( $_FILES ) ) {
foreach ( $_FILES as $input => $file_data ) {
if ( isset( $uploaded_files[ $input ] ) ) {
continue;
}
// Normalize single file uploads to match multi-file structure.
$uploaded_files[ $input ] = [
[ 'uploaded_filename' => $file_data['name'] ?? '' ]
];
}
}
if ( empty( $uploaded_files ) ) {
return $validation_result;
}
foreach ( $uploaded_files as $input => $files_data ) {
$field_id = str_replace( 'input_', '', $input );
$field = GFAPI::get_field( $form, $field_id );
if ( ! $field ) {
continue;
}
foreach ( $files_data as $file_data ) {
if ( ! preg_match( '/[¹²³–]/', $file_data['uploaded_filename'] ) ) {
continue;
}
$validation_result['is_valid'] = false;
$field->failed_validation = true;
$field->validation_message = 'Nome do arquivo não deve conter caracteres especiais.';
}
}
return $validation_result;
}
@mrcasual Please check the comments on the PR here https://github.com/GravityKit/GravityView/pull/2104
Reopening because while we made some advances here, it's still not good enough.
Here's a new video explaining what's going on: https://www.loom.com/share/9956641a40334cd4b340a5cfcf8561de
We need to:
Correcting these two items above will prevent the bug shown in the video.
I was able to upload more files than what was set in Gravity Forms:
Bonus: When working on this bug, see if this can also be fixed in the same attempt: https://github.com/GravityKit/GravityView/issues/1002