I have a cred post form with an image upload field.
I would like to limit the max-width and/or max-height of the pictures that users are allowed to upload.
I have seen on this page:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
that it should be possible to set max_width and max_height of image fields.
I am not sure if I understand it right, but I put the argument in my cred field like this:
[cred_field field='stort-billede3' force_type='field' class='form-control' max_width="1200px"]
But when users upload image from the post form, no erros is shown if the uploaded image is over 1200px in width. The image is just uploaded with the form submit.
I want the form to send an error to the screen that the image is too width and/or too heigh (in pixels), and make the form not possible to submit before the error is corrected by the user.
When it dosen't seem to work with the above solution - how do I do it?
Best regards,Poul P
That is intended for the display of the preview, not for the validation of uploaded media.
To validate the upload size you'd have to either set WordPress wide restrictions or use Toolset Forms validation Code:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
There are also code examples on this here https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_ajax_upload_validate
Some custom code samples are also visible in the forum like https://toolset.com/forums/topic/limit-upload-file-size-for-repeating-image-custom-field/.
This would be the right way to validate the size, please let me know if you need further help with this.
Hi,
The links you provide show examples of validating the SIZE. But it was not the size of the image, I want to validate, But the width (in pixel) and/or height (in pixel). And set a max height in pixel and/or max width in pixel, when users upload images.
Best, Poul
Hi,
Can you please give a working example of how to implement/use a cred field with argument max_width or max_height?
I am trying to put the argument in the cred field in the post form, and in the content-template/view (the intented use according to you)...but nothing happens...the image width/height looks the same no matter what I do.
Is it the image itself that should be adjusted accoring to the value of the max_height/max_width?
So can you give me an example of how to/where to use theses iamge width/height arguments, and what effect it should have to use them?
best regards,
Poul P
Hi,
can you tell me when I can expect to hear from you? I need feedback/answer to my two last replies..
Best regards,
Poul
I apologize that you hear so late from me, I am on weekends Sunday and Monday, that is why the delay.
As I mentioned, these ShortCode attributes are not for validation, but to decide how wide or tall the image shall be in the preview.
You need to apply custom code logic to have such validation in Toolset Forms, wether you validate size (which is just an example) or width, type, or other aspects of anything uploaded.
To automatically adjust an image on upload to such definitions requires even more custom code logic, as there is no application that does that automatically in Toolset.
I understand you want to make sure, the users do not upload any image bigger (in width and height) than a certain size.
You can ensure that by applying custom validation to the Toolset Forms, in PHP Code.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
For example, here is a code sample (that will need to be adapted to your site/use-case) that does exactly that with the Featured Image in a Toolset form:
https://toolset.com/forums/topic/featured-image-allowed-upload-sizes/#post-907608
As you can see it uses several PHP methods that are not part (or implemented natively) in Toolset.
I can help review such code, but I cannot provide a fully customized example that can be used directly. If you require custom code work help, the Toolset Contractors can be a good headstart: https://toolset.com/contractors/
Please let me know if I can help review or further explain the custom code.
Thank you
Too slow support. Did not read my questions. Answer on different thing that I have asked about.
I do not understand what I did wrong. Please allow me to help you and correct any mistake I made.
You are asking to validate a field for its width and height, correct?
This cannot be done with ShortCode attributes.
It can be done with the Code above provided.
As mentioned, the slowness of weekend support is expected, due to my unconventional weekends which are adjusted to help you as well on "traditional" weekends.
I am sure you can understand this.
Please let me know if you need more help here.