Created
December 7, 2016 23:00
-
-
Save Shelob9/710b44a8f928d304c7af56a9887f842e to your computer and use it in GitHub Desktop.
Examples of using the caldera_forms_mailer filter. See https://calderaforms.com/doc/caldera_forms_mailer/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'caldera_forms_mailer', function( $mail, $data, $form ) { | |
//MAKE SURE TO CHANGE FORM ID | |
if( 'CF1243hiMatt' == $form[ 'ID' ] ) { | |
//$data has all of the field data for submission | |
//change this to your field ID | |
$field_id = 'cf1234hiKevin'; | |
if( ! empty( $data[ $field_id ] ) ){ | |
//create temporary file, see: http://php.net/manual/en/function.tmpfile.php | |
$temp_file = tmpfile(); | |
//write field value to that file | |
fwrite( $temp_file, $data[ $field_id ] ); | |
$mail[ 'attachments' ][] = $temp_file; | |
} | |
} | |
return $mail; | |
}, 10, 3 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'caldera_forms_mailer', function( $mail, $data, $form ) { | |
//MAKE SURE TO CHANGE FORM ID | |
if( 'CF1243..' == $form[ 'ID' ] ) { | |
//$data has all of the field data for submission | |
//Presuming that fld1235 is name. | |
//Presuming that fld54321 has a post ID for a post with useful meta data, like a phone number for a store location. | |
$name = $data[ 'fld1235' ]; | |
$id = $data[ 'fld54321' ]; | |
$phone_number = get_post_meta( $id, 'phone_number', true ); | |
$message = "Thanks for getting in touch {$name} we will get back to you soon. If you have immediate questions, the phone number for our closest store is {$phone_number}."; | |
$mail[ 'message' ] = $message; | |
} | |
return $mail; | |
}, 10, 3 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'caldera_forms_mailer', function( $mail, $data, $form ) { | |
//MAKE SURE TO CHANGE FORM ID | |
if( 'CF1243..' == $form[ 'ID' ] ) { | |
$mail[ 'recipients' ][] = 'luke@skywalker.com'; | |
} | |
return $mail; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment