add default form

This commit is contained in:
2026-05-05 22:49:11 +02:00
parent 44653283c8
commit dbd4931458
2 changed files with 29 additions and 22 deletions

View File

@@ -37,6 +37,12 @@ function go_form_activate() {
PRIMARY KEY (id), PRIMARY KEY (id),
KEY form_id (form_id) KEY form_id (form_id)
) $charset;"); ) $charset;");
// Add default form if none exist
$existing_forms = $wpdb->get_var("SELECT COUNT(*) FROM $forms");
if ($existing_forms == 0) {
$wpdb->insert($forms, ['name' => 'Default Form']);
}
} }
register_activation_hook(__FILE__, 'go_form_activate'); register_activation_hook(__FILE__, 'go_form_activate');
@@ -48,7 +54,6 @@ function go_form_uninstall() {
register_uninstall_hook(__FILE__, 'go_form_uninstall'); register_uninstall_hook(__FILE__, 'go_form_uninstall');
// ========== Helpers ========== // ========== Helpers ==========
function go_form_get_rank_dropdown($selected = 0) {
$ranks = [ $ranks = [
0 => '30k', 1 => '29k', 2 => '28k', 3 => '27k', 4 => '26k', 0 => '30k', 1 => '29k', 2 => '28k', 3 => '27k', 4 => '26k',
5 => '25k', 6 => '24k', 7 => '23k', 8 => '22k', 9 => '21k', 5 => '25k', 6 => '24k', 7 => '23k', 8 => '22k', 9 => '21k',
@@ -57,19 +62,11 @@ function go_form_get_rank_dropdown($selected = 0) {
20 => '10k', 21 => '9k', 22 => '8k', 23 => '7k', 24 => '6k', 20 => '10k', 21 => '9k', 22 => '8k', 23 => '7k', 24 => '6k',
25 => '5k', 26 => '4k', 27 => '3k', 28 => '2k', 29 => '1k', 25 => '5k', 26 => '4k', 27 => '3k', 28 => '2k', 29 => '1k',
30 => '1d', 31 => '2d', 32 => '3d', 33 => '4d', 34 => '5d', 30 => '1d', 31 => '2d', 32 => '3d', 33 => '4d', 34 => '5d',
35 => '6d', 36 => '7d', 37 => '8d', 38 => '9d', 39 => '1p', 40=> '2p', 35 => '6d', 36 => '7d', 37 => '8d', 38 => '9d', 39 => '1p',
41 => '3p', 42=> '4p', 43 => '5p', 44=> '6p', 45 => '7p', 46 => '8p', 47 => '9p' 40 => '2p', 41 => '3p', 42 => '4p', 43 => '5p', 44 => '6p',
45 => '7p', 46 => '8p', 47 => '9p'
]; ];
$html = '<select name="rank" id="rank">\n';
foreach ($ranks as $value => $label) {
$selected_attr = selected($value, $selected, false);
$html .= " <option value='{$value}'{$selected_attr}>{$label}</option>\n";
}
$html .= "</select>";
echo $html;
}
function go_form_get_forms() { function go_form_get_forms() {
global $wpdb; global $wpdb;
return $wpdb->get_results("SELECT * FROM {$wpdb->prefix}go_form_forms ORDER BY name ASC"); return $wpdb->get_results("SELECT * FROM {$wpdb->prefix}go_form_forms ORDER BY name ASC");
@@ -78,26 +75,28 @@ function go_form_get_forms() {
function go_form_get_entries($form_id) { function go_form_get_entries($form_id) {
global $wpdb; global $wpdb;
return $wpdb->get_results($wpdb->prepare( return $wpdb->get_results($wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}go_form_entries WHERE form_id = %d ORDER BY created_at DESC", "SELECT * FROM {$wpdb->prefix}go_form_entries WHERE form_id = %d ORDER BY rank DESC",
$form_id $form_id
)); ));
} }
function go_form_render_entries_table($entries, $show_delete = false) { function go_form_render_entries_table($entries, $show_delete = false) {
global $ranks;
if (empty($entries)) { if (empty($entries)) {
echo '<p>No entries yet.</p>'; echo '<p>No entries yet.</p>';
return; return;
} }
$headers = ['ID', 'First Name', 'Last Name', 'Country', 'Club', 'Rank', 'Email', 'EGD Number', 'Date Added']; $headers = ['First Name', 'Last Name', 'Country', 'Club', 'Rank', 'Email', 'EGD Number', 'Date Added'];
if ($show_delete) $headers[] = 'Action'; if ($show_delete) $headers[] = 'Action';
echo '<table class="'.($show_delete ? 'wp-list-table widefat fixed striped' : 'go-entries-table').'"> echo '<table class="'.($show_delete ? 'wp-list-table widefat fixed striped' : 'go-entries-table').'">
<thead><tr><th>'.implode('</th><th>', $headers).'</th></tr></thead><tbody>'; <thead><tr><th>'.implode('</th><th>', $headers).'</th></tr></thead><tbody>';
foreach ($entries as $e) { foreach ($entries as $e) {
echo '<tr><td>'.esc_html($e->id).'</td><td>'.esc_html($e->first_name).'</td><td>'.esc_html($e->last_name).'</td> echo '<tr><td>'.esc_html($e->first_name).'</td><td>'.esc_html($e->last_name).'</td>
<td>'.esc_html($e->country).'</td><td>'.esc_html($e->club).'</td><td>'.esc_html($e->rank).'</td> <td>'.esc_html($e->country).'</td><td>'.esc_html($e->club).'</td><td>'.esc_html($ranks[$e->rank]).'</td>
<td>'.esc_html($e->email).'</td><td>'.esc_html($e->egd_number).'</td><td>'.esc_html($e->created_at).'</td>'; <td>'.esc_html($e->email).'</td><td>'.esc_html($e->egd_number).'</td><td>'.esc_html($e->created_at).'</td>';
if ($show_delete) { if ($show_delete) {
@@ -155,7 +154,7 @@ function go_form_shortcode($atts) {
if (isset($_GET['form_success']) && $_GET['form_success'] == 1) if (isset($_GET['form_success']) && $_GET['form_success'] == 1)
$msg = '<div>Entry added successfully!</div>'; $msg = '<div>Entry added successfully!</div>';
elseif (isset($_GET['form_error'])) { elseif (isset($_GET['form_error'])) {
$errors = ['1' => 'Please fill in all required fields.', 'rank' => 'Rank must be 0-40.', 'email' => 'Please enter a valid email.']; $errors = ['1' => 'Please fill in all required fields.', 'rank' => 'Rank must be 0-47.', 'email' => 'Please enter a valid email.'];
$msg = '<div>'.esc_html($errors[$_GET['form_error']] ?? $errors['1']).'</div>'; $msg = '<div>'.esc_html($errors[$_GET['form_error']] ?? $errors['1']).'</div>';
} }

View File

@@ -53,7 +53,17 @@
<button type="button" id="egd-search" class="button">Search EGD</button> <button type="button" id="egd-search" class="button">Search EGD</button>
<label for="country">Country:</label><input type="text" name="country" id="country"> <label for="country">Country:</label><input type="text" name="country" id="country">
<label for="club">Club:</label><input type="text" name="club" id="club"> <label for="club">Club:</label><input type="text" name="club" id="club">
<label for="rank">Rank:</label><?php go_form_get_rank_dropdown(); ?> <label for="rank">Rank:</label>
<select name="rank" id="rank">
<?php
global $ranks;
foreach ($ranks as $value => $label) {
echo "<option value='{$value}'>{$label}</option>\n";
}
?>
</select>
<label for="email">Email:</label><input type="email" name="email" id="email"> <label for="email">Email:</label><input type="email" name="email" id="email">
<label for="egd_number">EGD Number:</label><input type="text" name="egd_number" id="egd_number"> <label for="egd_number">EGD Number:</label><input type="text" name="egd_number" id="egd_number">
<div id="egd-popup-overlay"> <div id="egd-popup-overlay">
@@ -77,9 +87,7 @@ document.addEventListener('DOMContentLoaded', function() {
const resultsDiv = document.getElementById('egd-results'); const resultsDiv = document.getElementById('egd-results');
const searchButton = document.getElementById('egd-search'); const searchButton = document.getElementById('egd-search');
const closeButton = document.getElementById('egd-popup-close'); const closeButton = document.getElementById('egd-popup-close');
console.log("WE ARE SET UP");
function fetchPlayers() { function fetchPlayers() {
console.log("HI");
const firstName = firstNameInput.value.trim(); const firstName = firstNameInput.value.trim();
const lastName = lastNameInput.value.trim(); const lastName = lastNameInput.value.trim();