CalderaWP / Caldera-Forms

Drag and drop, responsive WordPress form builder.
https://CalderaForms.com
GNU General Public License v2.0
187 stars 166 forks source link

email body gets replaced with url to uploaded file #3549

Open hannesdorn opened 4 years ago

hannesdorn commented 4 years ago

What Version Of Caldera Forms, WordPress and PHP Are You Using?

WordPress Version: 5.4.1 PHP Version: 7.4.6 MySQL Version: 8.0.20 Caldera Forms Version: 1.8.11 WP_DEBUG: 1

Does Your Issue Persist When You Disable All Other Plugins and Switch To The Default Theme?

yes

What Is The Unexpected Behaviour?

The email body is replaced with the url to the file.

The problem is in classes\magic\doer.php line 85:

if( Caldera_Forms_Field_Util::is_file_field( $field, $form ) ){
    $_value = self::magic_image( $field, $entry, $form );
    if( false !== $_value ){
        $value = $_value;
    }

    continue;

}

$value = $_value overwrites the email body.

Possible solution:

if( Caldera_Forms_Field_Util::is_file_field( $field, $form ) ){
    $_value = self::magic_image( $field, $entry, $form );
    if( false !== $_value ){
        // $value = $_value;
        $value = str_replace( $matches[ 0 ][ $key ], $_value, $value );
    }
    continue;
}
New0 commented 4 years ago

Hello @hannesdorn , thank you for reporting this issue. Could you detail how to reproduce it?

hannesdorn commented 4 years ago

It is a very simple form: 1 HTML field 5 FILE fields 1 SUBMIT button

vollmachten-hochladen-export.json.txt

New0 commented 4 years ago

Thank you @hannesdorn , I could reproduce an issue with the email content as it is set in the form shared.

What work as a workaround for your email content example is :

Vollmachten von {user:last_name} {user:first_name} ({user:user_login})

{summary}

Now, I'm marking this to be researched, the wrong email content gets set in classes/save.php l233 where the Caldera_Forms::do_magic_tags() function returns one file name.

Thanks again for reporting this @hannesdorn

hannesdorn commented 4 years ago

Please note my suggested solution:

// $value = $_value;
$value = str_replace( $matches[ 0 ][ $key ], $_value, $value );