Tell us what you are trying to do?
- I am trying to validate CRED forms to limit files upload to specific file types of limited size.
I created a custom code snippet with the following code below and it simply doesn't work: nothing happens, no errors in logs etc.
Not sure what a I doing wrong.
add_filter('cred_form_validate','cred_filetype_size_validation',10,2);
function cred_filetype_size_validation($field_data, $form_data)
{
if ( ( (251 == $form_data['id']) OR (721 == $form_data['id']) ) AND (isset($_FILES['wpcf-scan-image-file']['value']['type'])) AND (isset($_FILES['wpcf-scan-image-file']['value']['size'])) AND ($_FILES['wpcf-scan-image-file']['value']['size'])>0 ) {
Hi Minesh,
thank you for your reply.
I added your code but it doesn't make any change either... I am still able to submit other than the requested files using specified forms.
Can you please share problem URL where you added your form as well as admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Thank you, Minesh.
The code you shared works with an error: it gives an error message with every submission, no matter which file type I use.
In PHP log I see the following PHP notice after form submissions:
"PHP Notice: Undefined variable: error_fields in /wp-content/toolset-customizations/validate-cred-file-uploads-order-report-forms.php on line 14"
Sorry, for the late response, Minesh. I thought I replied to you but looks like I did not reply to your last message.
I tested the code you kindly advised. Unfortunately, it works not correctly: no matter what file I upload it gives an error message that the file type or size is not right.
Hi Minesh, thank you again!
I made tests and the previous issue is gone.
However, there are couple of other things not right:
- for some reason, I get an error when upload .zip file.
- also, when I try to upload DICOM (.dcm) I get another error right after adding the file (before submission). Here is the HTML element with an error message:
<small for="cred_form_721_1_1_scan-image-file" generated="true" class="wpt-form-error">This field is required.</small>
I checked that user roles that submit these forms with files has access to "publish and edit own" media files, not only read them.
When I deactivate access plugin, this issue gone. I am not sure what settings would be right to allow uploads of .dmc files...
I've also adjusted the related validation hook to allow zip files.
Now, if it still does not work you will have to send me sample .zip and .dcm files you are trying to upload and I'll check further whats going wrong with the files you are trying to upload.
Hi Minesh.
Thank you so much.
There is no issue now with .zip files.
However, I still experience issues with .dcm files.
I use sample files for tests from these sites: hidden link
and hidden link