Skip Navigation

[Resolved] Array to String Conversion Error When Image Size Validation Fails

This thread is resolved. Here is a description of the problem and solution.


The cred_form_validate filter hook throws PHP waring in editing post form.


This is fixed in next version of Toolset Forms plugin.

Relevant Documentation:

This support ticket is created 2 years, 8 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/Hong_Kong (GMT+08:00)

This topic contains 9 replies, has 2 voices.

Last updated by julieP 2 years, 8 months ago.

Assisted by: Luo Yang.


I have a cred validation hook to restrict the size & type of image files uploaded on the frontend. The Media Library checkbox on form is unchecked :-

add_filter('cred_form_validate', 'ts_validate_data_222',10,2);
function ts_validate_data_222($field_data, $form_data){
      $form_ids = array( 222 => true );

    if ( isset( $form_ids[ $form_data['id'] ] ) ) {
        if ( !empty( $fields['wpcf-logo']['value'] ) )  {
            if ( ( $file_type_logo != 'image/jpeg' ) || ( $file_size_logo > 10240 ) ) {
                $errors['logo'] = 'Please check your image is a JPG/JPEG and smaller than 10KB in size';
    return array($fields,$errors);

I've not had any issues with uploading files for ages but now, if the image fails the validation, several thing shappen:-

1. a Toolset generated notice "Because validation failed, please upload the files again" appears
2. the word "Array" is displayed instead of the cred field, and the "choose file" button only shows if the user manually clicks on the X
3. my debug log has these entries:-

"Warning: md5() expects parameter 1 to be string, array given in /home/xxxx/public_html/wp-content/plugins/cred-frontend-editor/application/models/field/wptoolset/class.abstract_credfile.php on line 144

Notice: Array to string conversion in /home/xxxx/public_html/wp-includes/formatting.php on line 1098

Notice: Array to string conversion in /home/xxxx/public_html/wp-includes/formatting.php on line 1098

Notice: Array to string conversion in /home/xxxx/public_html/wp-includes/formatting.php on line 1098

Notice: Array to string conversion in /home/xxxx/public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/classes/class.eforms.php on line 598

Notice: Array to string conversion in /home/xxxx/public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/classes/class.eforms.php on line 598

Notice: Array to string conversion in /home/xxxx/public_html/wp-includes/formatting.php on line 1098"

Several questions arise out of this:-

1. how do I either prevent generation of the Toolset message (I have already covered this requirement elsewhere on the form, your format just doesn't fit with my design nor does it appear where I want it to) OR how do I hide it?

2. What's the issue causing the errors?

3. Is this a known issue?



Since it is a custom codes problem, please provide a test site with the same problem, also point out the problem page URL and form URL, where I can edit your custom PHP codes, I need to test and debug it in a live website, thanks


I wouldn't call this a custom code problem; the CRED form provides the ability to use or not use the Media Library and the validation code was provided by Toolset support staff.

Additionally, if I remove the validation code and change my WordPress site settings to disallow the upload of jpg and jpeg files and then try to upload one, I get a different error:- "/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/classes/Form_Builder_Helper.php on line 1963" along with an atrociously worded form error "Error some required upload field failed".

Furthermore if I remove the image validation code and validate only the other (single line) field on the form to ensure it contains a value (another routine snippet provided by Toolset), the originally reported error appears concerning the image even if the user doesn't try to change it.

Somewhere during the form processing, certain validation failures trigger the removal of images which is clear because after validation of the form, an array of values are expected that don't exist.

I think you need to investigate from your end. Also, given the time difference between our locations, it would be preferable if this could be passed to a support staff member who is closer to Europe.


Since you are using option "Use the WordPress Media Library manager for image, video, audio, or file fields", so your user will be able to upload files with WordPress Media Library before he submit the form.

In this case, you need to use anther filter hook "cred_form_ajax_upload_validate" to validate the uploaded files, see our document:
This hook provides custom validation for files that are uploaded using AJAX


In my original thread I told you the Media Library box is UNCHECKED


Sorry the misunderstanding, I have tried the PHP codes you mentioned above in my localhost with a fresh WP installation, but don't see the PHP error message you mentioned above.

So the problem you mentioned above is abnormal, please check these:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, deactivate all custom PHP/JS code snippets, and test again

3) If the problem still persists, please provide database dump file(ZIP file) of your website, you can put the package files in your own google drive disk, share the link only, also point out the problem page URL and form URL, I need to test and debug it in my localhost, thanks

And you can hide the form message by these:
Edit your post form, find and remove the message shortcode:
[cred_field field='form_messages' class='alert alert-warning']


I'm just doing a bit more troubleshooting of my own. I've discovered that the warnings only appear when the edit version of the form is submitted. Using a clone of the edit form which I then set to create a post, the warnings don't appear.

When you tested, did you use a create post form or an edit post form?


Thanks for the details, I can reproduce the same problem in my localhost, and have escalate this issue, will update here if there is any news.


Our developers have provided a hotfix for this issue, you can download it here:
hidden link

Unzip above file, use the file "base.php" to replace the same file under Toolset Forms plugin folder file:application\models\form\base.php

Please test it and feedback if the problem is fixed, thanks


Hi Luo

Thanks for the hot fix which I can confirm is working. Appreciate the quick turnaround by the developers.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.