I would like to set my site's upload file type and data size limit. I would like to know for the whole site or individual forms( i have like 8 different forms)
I would like to set each file for max 5Mb and accept only jpg,png,gif,pdf,doc. and if the user try to
upload something other than this scope, I would like to
display an error message.
I think this is very important and basic feature for wp toolset form. But, why isn't it a basic feature??
I really don't get it though.
I try to use some code snippets from other posts. so far unsuccessful.
Is there any documentation that you are following?
I copy the code from the link you gave me and modify it as below.
If I understand this correctly, it should limit for form id 1311 upload only PDF upto 5mg for a field "financial-info", right?
I use codesnipet plugin and added there. But it seems not working. I was able to upload 6mb pdf, and some jpeg as well.
Could you explain this little more?
add_filter('cred_form_validate','cred_filetype_size_validation',10,2);
function cred_filetype_size_validation($field_data, $form_data)
{
// Field data are field values and errors
list($fields,$errors)=$field_data;
//Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
if (( 1311 == $form_data['id']) && (isset($_FILES['wpcf-financial-info']['type'])) && (isset($_FILES['wpcf-financial-info']['size']))) {
//Retrieve file type
$file_type_uploaded=$_FILES['wpcf-financial-info']['type'];
//Validate files uploaded, make sure its PDF file type AND not more than 5000kB
if (!( ('application/pdf' == $file_type_uploaded) && ($file_size_uploaded < 5000000) )) {
$errors['pers-financial-info']='Sorry the file you have uploaded is not of the correct type or exceeded 100kB limit.';
}
}
//return result
return array($fields,$errors);
}
I've tested the code that you've shared and it worked as expected on my test website. I just had to fix this line:
$errors['pers-financial-info']='Sorry the file you have uploaded is not of the correct type or exceeded 100kB limit.';
To:
$errors['financial-info']='Sorry the file you have uploaded is not of the correct type or exceeded 100kB limit.';
Also, this file validation approach will only work if the option "Use the WordPress Media Library manager for image, video, audio, or file fields" is not checked in the form's settings.
Is there anyway to change what's written on my original post? I would like to hide my site name from this post. Could you delete it? also, Please delete this reply aswell after deleting my site name if possible?
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.