Support » Plugin: Contact Form 7 » Mandatory file validation is not working

  • Hi,

    I have installed the latest version of the plugin and can see the additional filters for files validation in the code, but these do not work if no file is sent (like for any mandatory fields).

    Basically, the [file* …] does not trigger any of the filters we could use programmatically to validate the field, and also the wpcf7_validate field does not account for the object at all (looking in the WPCF7_FormTag, there is no [type] => file*). Am I missing something or using this in the wrong way?

    Thank you for your time and for sharing this awesome tool!
    Iulia

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Where can we see the website in question?

    Thread Starter Iulia Cazan

    (@iulia-cazan)

    Hi,

    The staging site is https://desiro.golive.ro/. In meanwhile, I came up with this solution (which is not that elegant).

    add_filter( 'wpcf7_validate', 'custom_file_validation', 30, 3 );
    
    /**
     * Validate custom file.
     *
     * @param  object $result Result object.
     * @param  object $tags   Form tags.
     * @param  array  $args   Form arguments.
     * @return object
     */
    function custom_file_validation( $result, $tags, $args = [] ) {
    	if ( ! empty( $_FILES['bonfiscal']['error'] ) ) {
    		if ( 1 === $_FILES['bonfiscal']['error'] ) {
    			$result->invalidate( 'bonfiscal', 'Fișierul trebuie să nu depășească 2MB.' ); // The size is too big.
    		} else {
    			$result->invalidate( 'bonfiscal', 'Fișierul nu a fost încărcat.' ); // The file was not selected.
    		}
    	}
    
    	return $result;
    }
    

    I can remove the filter, to revert the code to the default behavior. Let me know how I can assist with troubleshooting.

    Regards,
    Iulia

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    What other plugins and theme do you use on the site?

    Thread Starter Iulia Cazan

    (@iulia-cazan)

    This is the list:

    • Twenty Twenty-One (twentytwentyone) @ 1.3
    • Contact Form 7 @ 5.4.1 by Takayuki Miyoshi
    • Contact Form CFDB7 @ 1.2.5.9 by Arshid
    • Custom Fonts @ 1.3.2 by Brainstorm Force
    • Elementor @ 3.2.5 by Elementor.com
    • SVG Support @ 2.3.18 by Benbodhi
    • Wordfence Security @ 7.5.4 by Wordfence
    • This reply was modified 3 months, 2 weeks ago by Iulia Cazan.
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.