Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

302
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda