Contact Form 7如何获取同名数组输入appliSkill[]的所有值并发送邮件?
How to Retrieve All Values from
appliSkill[] Array Fields in Contact Form 7 Emails Hey there! I've dealt with this exact issue when building dynamic forms with Contact Form 7, so let me walk you through the solution step by step:
Step 1: Add Custom PHP Code to Process the Array Data
Contact Form 7 doesn't natively handle array-named fields like appliSkill[] in its default mail tags, so we'll use a CF7 hook to process the data before the email is sent.
Add this code to your theme's functions.php file (or a custom plugin if you prefer):
add_action('wpcf7_before_send_mail', 'process_appli_skill_array'); function process_appli_skill_array($contact_form) { // Get the submitted form data $submission = WPCF7_Submission::get_instance(); if (!$submission) return; $posted_data = $submission->get_posted_data(); // Check if the appliSkill array exists if (isset($posted_data['appliSkill']) && is_array($posted_data['appliSkill'])) { // Filter out empty values (optional but recommended) $clean_skills = array_filter($posted_data['appliSkill'], function($skill) { return !empty(trim($skill)); }); // Convert the array to a formatted string (e.g., bullet points) $skill_list = implode("\n- ", $clean_skills); // Add a leading bullet if there are skills if (!empty($skill_list)) { $skill_list = "- " . $skill_list; } // Add the processed list as a custom mail tag $submission->add_posted_data('appli_skill_list', $skill_list); } }
Step 2: Use the Custom Mail Tag in Your CF7 Email
Head over to your Contact Form 7 editor, go to the Mail tab, and insert the custom tag [appli_skill_list] wherever you want to display the full list of skills.
For example, in your email body:
Applicant's Skills: [appli_skill_list]
Quick Customization Tips
- If you prefer comma-separated values instead of bullet points, replace
implode("\n- ", $clean_skills)withimplode(', ', $clean_skills). - Remove the
array_filterblock if you want to include empty fields in the email (though this isn't usually recommended for user experience). - Always test the form after setting this up—submit a form with multiple filled skills to confirm the email displays everything correctly.
内容的提问来源于stack exchange,提问作者Nash
相关产品推荐
相关产品推荐

