Skip Navigation

[Resolved] The CRED form is only allowing .jpg and .png extensions on uploaded files

This support ticket is created 3 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 3 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2177473

Tell us what you are trying to do?
My CRED form is only allowing .jpg and .png extensions on uploaded files. Can you tell me how to force it to accept other mime types? I can see how to further restrict it but not how to override restrictions. Switching over to the built-in media uploader allows the file to be uploaded but - subsequently - the CRED form would not validate. Result was that the media was uploaded/added but the form cannot be submitted. note there are three very similar forms on this page but the issue happened even if only one form was present.

temporary solution was removing the “js-wpt-validate” class from the input in order to stop the upload file input from getting validated. I had to make it remove the class when the button is clicked on rather than when the input is rendered because the class js-wpt-validate added sometime after render. Can you help me understand what's going on? should this class be removed via some setting? or should the validation be controlled somewhere I've missed?

the js to remove “js-wpt-validate” class from the input is below:

window.addEventListener('load', function() {
const uploadElements = jQuery('input[name="wpcf-resource-upload"]');
for (uploadElement of uploadElements) {
jQuery(uploadElement).on("click", function(e) {
jQuery(e.currentTarget).removeClass('js-wpt-validate');
});
}
});

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
https://developer.wordpress.org/reference/hooks/upload_mimes/

Is there a similar example that we can see?

What is the link to your site?
transportationmanagement.us/mndot

#2178323

Hi,

Thank you for contacting us and I'd be happy to assist.

If you're referring to the image type field, Toolset supports all image mime types allowed on the website, e.g:
jpg, jpeg, jpe, gif, png, bmp, tiff, tif, webp, ico, heic

Note: The "svg" is also supported but only if its support is enabled on the website.
( ref: hidden link )

If, you'd like your fields to accept mime types other than an image, then it would be better to use the "file" type field instead of the "image" type field and then use the "cred_form_validate" hook, to limit the allowed file types.
( https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate )

In case, your image field is only accepting the .jpg and .png files, then it would be a good idea to check all the custom code snippets added to the website to see if any custom validation rule is being applied to it.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar