Files
2026-05-12 21:11:39 +02:00

50 lines
1.2 KiB
PHP

<?php
go_form_admin_action('export_csv');
if (!isset($_POST['value_one'])) {
wp_redirect(admin_url('admin.php?page=go-form-settings'));
exit;
}
$form_id = intval($_POST['value_one']);
$form = go_form_get_form_by_id($form_id);
$form_name = $form ? $form->name : 'Unknown Form';
$entries = go_form_get_entries($form_id);
$custom_fields = go_form_get_custom_fields($form_id);
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="go-form-' . sanitize_title($form_name) . '-export.csv"');
$output = fopen('php://output', 'w');
// Build header row
$header = ['N', 'First Name', 'Last Name', 'Country', 'Club', 'Rank', 'Rating', 'EGD Number', 'Date Added'];
foreach ($custom_fields as $field) {
$header[] = $field->field_name;
}
fputcsv($output, $header);
foreach ($entries as $i => $e) {
global $ranks;
$row = [
$i,
$e->first_name,
$e->last_name,
$e->country,
$e->club,
$ranks[$e->rank] ?? '',
$e->rating,
$e->egd_number,
$e->created_at
];
// Add custom field values
foreach ($custom_fields as $field) {
$value = go_form_get_custom_value($e->id, $field->id);
$row[] = $value;
}
fputcsv($output, $row);
}
fclose($output);