• Resolved sgroup

    (@sgroup)


    Hi,

    I have a form with a file upload field and I made a function to attach the uploaded file before sending the email. It looks like this:

    function filter_email_attachments( $attachments, $email, $form, $fields ) {
        $file = af_get_field( 'file' );
        $filedir = get_attached_file( $file );
        $attachments[] = $filedir;
        return $attachments;
    }
    add_filter( 'af/form/email/attachments/key=form_2c348ef543a81', 'filter_email_attachments', 10, 4 );

    This works great, but I was wondering if it is possible to use a repeater field, so a user can upload multiple files. How can I attach multiple files to my function?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi!

    If you use af_get_field with a repeater you’ll get all the rows. As such you should be able to add them all like this:

    
    function filter_email_attachments( $attachments, $email, $form, $fields ) {
        $repeater = af_get_field( 'REPEATER_FIELD_NAME' );
        foreach ( $repeater as $row ) {
           $file = $row['file'];
           $filedir = get_attached_file( $file );
           $attachments[] = $filedir;
        }
       
        return $attachments;
    }
    add_filter( 'af/form/email/attachments/key=form_2c348ef543a81', 'filter_email_attachments', 10, 4 );
    

    Change REPEATER_FIELD_NAME to whatever your repeater is called. Also, possibly change the name in the loop if you subfield is not called “file”.

    Hope this helps!

    Thread Starter sgroup

    (@sgroup)

    Works great, thanks!

    Thread Starter sgroup

    (@sgroup)

    Hi, after plugin update this no longer seems to work. Any idea?

    Thanks!

    Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi!

    Which update are you referring to?

    Thread Starter sgroup

    (@sgroup)

    Hi,

    I’ve updated the plugin from version 1.6.0 (which worked perfectly) to 1.6.4

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Image attachment repeater’ is closed to new replies.