Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • I had to deal with the same the last day.

    I didn’t found any option in CF7 and the plugins I tried didn’t match my requirements.

    So I played around a little bit and found out that CF7 works just fine if the input name is an array and the multipe attribute is set.

    #1 Add multiple option to your file tag (like you already did)

    #2 Add this filter to functions.php or whatever:
    Disclaimer: This isn’t tested, but on my dev environment yet.

    add_filter( 'wpcf7_form_tag', function ( $tag ) {
    if ( 'file' === $tag['basetype'] ) { // file fields only
    // check for a
    multiple option
    foreach ( (array) $tag['options'] as $option ) {
    if ( str_starts_with( $option, 'multiple' ) ) {
    // make field name an array and add multiple attribute
    add_filter( 'wpcf7_form_elements', function ( $content ) use ( $tag ) {
    return str_replace(
    " name=\"{$tag['name']}\"",
    " name=\"{$tag['name']}[]\" multiple=\"multiple\"",
    $content );
    } );

    break;
    }
    }
    }

    return $tag;
    } );

    That’s it. Now you can select multiple files and they get attached to the email.

    • This reply was modified 8 months, 1 week ago by enoks.
    • This reply was modified 8 months, 1 week ago by enoks.
    Thread Starter enoks

    (@enoks)

    Fixed with version 3.5

    Thread Starter enoks

    (@enoks)

    Thanks for fast response and I’m glad I could help.

    For everyone who’s struggling with the same issue … this will do the trick till the release:

    add_filter( 'register_meta_args', function( $args, $defaults, $object_type, $meta_key ) {
        if ( in_array( $meta_key, array( '_locale', '_original_post' ) ) ) {
            $args += array(
                'auth_callback' => function () {
                    return current_user_can('edit_posts' );
                }
            );
        }
        return $args;
    }, 10, 4 );
    • This reply was modified 5 years, 2 months ago by enoks.
Viewing 3 replies - 1 through 3 (of 3 total)