Files
wp-go-form/go-form-plugin/export/csv.php
Nikola Petrov 2d537f07dd Add complete custom fields implementation and entry editing
- Add custom field CRUD in admin UI (create, read, update, delete)
- Display custom fields on frontend form with proper field types
- Save custom field values on form submission
- Display custom field columns in entries table (admin and public)
- Include custom field values in all export formats (CSV, PairGoTh, OpenGotha, McMahon)
- Add Edit button and form for entries
- Update entry handler to support editing with custom field values
- Add success/error notices for all admin actions

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-05-12 13:02:33 +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 = ['ID', '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 $e) {
global $ranks;
$row = [
$e->id,
$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);