Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

303
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda