dimanche 22 mars 2015

How can I add different attachments to Contact Form 7 depending on dropdown selection?


I would like Contact Form 7 to add an attachment to the recipient that depends on a dropdown selection. So in the example below I'm trying to get it to attach "instructions-blue.pdf" only if the user selects "Blue" from the dropdown, and likewise for "instructions-green.pdf" etc. I've cobbled the code below together from various online searches but to be fairly honest it's all a shot in the dark for me. Basically I'm trying to get it to call the dropdown selection and append it to "instructions-" for the filename. At the moment it will send the email but there is no attachment. Any help would be grandly appreciated!



add_action('wpcf7_before_send_mail','send_pdf');
function send_pdf( $cf7 ) {
$id = $cf7->id();
if ($id==694){
$submission = WPCF7_Submission::get_instance();
$filename = $cf7->form['color']; //"color" is the name of the dropdown field.
$submission->add_uploaded_file('pdf', get_template_directory_uri().'/instructions/instructions-'.$filename.'.pdf');
}
}




Aucun commentaire:

Enregistrer un commentaire