Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
Contact Form 7 - Conditionally/Dynamically Attach Local Files to Email Based on Input Selection

I have a number of checkboxes that indicate the item that is ordered through our online order form system. For each item selected there is a corresponding .pdf file that is stored on our server that should be included in the email.

For instance, they would select three out of five of the checkboxes below and then the three .pdfs that go with those selections are attached to the email.

[checkbox SR-010-01]
[checkbox SR-010-02]
[checkbox SR-010-03]
[checkbox SR-010-04]
[checkbox SR-010-05]

Contact Form 7 allows for files to be attached as a default, but I can't seem to find a way to add them based on whatever selection is made.

Is there maybe a way to use the CF7 file upload system to upload files that already exist locally? There might be a Javascript based solution that way.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

sure, use the wpcf7_mail_components filter which allows you to interact with the mail structure before being sent out,

add_filter('wpcf7_mail_components', 'attach_files_based_on_field',10,3);
function attach_files_based_on_field($components, $form, $mail){
  //get the form submited data
  $submission = WPCF7_Submission::get_instance();
  $data = $submission->get_posted_data('my-checkbox-field');
  //check the values ($data) of your checkbox field 
  //and decide which file to attach
  $components['attachments'][] = '/path-relative-to-wp-content-folder/file.name';
  return $components;
}

NOTE: the CF7 plugin will seek files to attach relative to the wp-content folder so you need to give file paths that relative to that folder.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!