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);