/** * Save Contact Form 7 submission data to custom database table */ function save_cf7_submission_to_custom_table($contact_form) { global $wpdb; // Check if the form ID matches the one we want to save if ($contact_form->id() != 92) { // Change this to your form ID return; } // Get posted data from Contact Form 7 $submission = WPCF7_Submission::get_instance(); if ($submission) { $data = $submission->get_posted_data(); // Define table name $table_name = $wpdb->prefix . 'tablesome_table_3126'; // Insert data into the custom table $wpdb->insert($table_name, array( 'column_1' => sanitize_text_field($data['your-select']), // שם מבקש התרומה 'column_2' => sanitize_email($data['your-email-from-table']), // כתובת מייל 'column_3' => sanitize_text_field($data['your-notes']), // הערות 'column_4' => sanitize_text_field($data['your-country']), // מדינה 'column_5' => sanitize_text_field($data['your-currency']), // מטבע 'column_6' => sanitize_text_field($data['your-donation-type']), // סוג תרומה 'donor_name' => sanitize_text_field($data['your-donor-name']), // שם נותן התרומה 'donor_contact' => sanitize_text_field($data['your-donor-contact']), // מספר טלפון או מייל של נותן התרומה )); } } add_action('wpcf7_before_send_mail', 'save_cf7_submission_to_custom_table'); /** * Populate Contact Form 7 fields from custom database table */ function populate_cf7_fields_from_table($tag) { if (in_array($tag->name, ['your-select', 'your-email-from-table', 'your-country', 'your-currency', 'your-donation-type'])) { global $wpdb; $table_name = $wpdb->prefix . 'tablesome_table_3126'; $results = $wpdb->get_results("SELECT * FROM $table_name"); $options = []; foreach ($results as $row) { switch ($tag->name) { case 'your-select': $options[] = esc_html($row->column_1); break; case 'your-email-from-table': $options[] = esc_html($row->column_2); break; case 'your-country': $options[] = esc_html($row->column_4); break; case 'your-currency': $options[] = esc_html($row->column_5); break; case 'your-donation-type': $options[] = esc_html($row->column_6); break; } } $tag->values = $options; $tag->labels = $options; } return $tag; } add_filter('wpcf7_form_tag', 'populate_cf7_fields_from_table', 10, 1);