Add notification email

This commit is contained in:
2026-07-05 20:26:56 +02:00
parent 08ae633d01
commit 2f06a8a4f1
5 changed files with 72 additions and 220 deletions
+1
View File
@@ -3,6 +3,7 @@
CREATE TABLE wp_go_form_forms (
id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
email varchar(255) DEFAULT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (id)
);
+46 -10
View File
@@ -17,6 +17,7 @@ function go_form_activate()
dbDelta("CREATE TABLE $forms (
id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
email varchar(255) DEFAULT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (id)
) $charset;");
@@ -172,6 +173,7 @@ function go_form_handle_submission()
wp_die('Security check failed');
global $wpdb;
global $ranks;
if (isset($_POST['form_id'])) {
$form_id = intval($_POST['form_id']);
} else {
@@ -230,16 +232,25 @@ function go_form_handle_submission()
}
}
// Send notification email
// $to = 'nikola@petrovv.com';
// $subject = 'New Go Tournament Registration';
// Send notification email if form has an email configured
$form = go_form_get_form_by_id($form_id);
if (!empty($form->email)) {
$to = $form->email;
$subject = 'New Go Tournament Registration';
$message = "A new player has signed up:\n\n";
$message .= "Form: {$form->name}\n";
$message .= "Form ID: {$form_id}\n";
$message .= "Name: {$data['first_name']} {$data['last_name']}\n";
$message .= "Country: {$data['country']}\n";
$message .= "Club: {$data['club']}\n";
$message .= "Rank: {$ranks[$data['rank']]}\n";
$message .= "Rating: {$data['rating']}\n";
$message .= "EGD Number: {$data['egd_number']}\n";
$message .= "Date: " . date('Y-m-d H:i:s') . "\n";
// $message = "A new player has signed up:\n\n";
// $message .= "Form ID: {$form_id}\n";
// $message .= "Name: {$data['first_name']} {$data['last_name']}\n";
// wp_mail($to, $subject, $message);
wp_mail($to, $subject, $message);
}
wp_redirect($_SERVER['HTTP_REFERER']);
exit;
@@ -299,7 +310,11 @@ function go_form_create_form()
go_form_admin_action('create_form');
if (isset($_POST['form_name']) && !empty($_POST['form_name'])) {
global $wpdb;
$wpdb->insert("{$wpdb->prefix}go_form_forms", ['name' => sanitize_text_field($_POST['form_name'])]);
$form_data = [
'name' => sanitize_text_field($_POST['form_name']),
'email' => isset($_POST['form_email']) ? sanitize_text_field($_POST['form_email']) : ''
];
$wpdb->insert("{$wpdb->prefix}go_form_forms", $form_data);
$new_form_id = $wpdb->insert_id;
$redirect_url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $new_form_id, 'created' => 1), admin_url('admin.php'));
wp_redirect($redirect_url);
@@ -311,6 +326,27 @@ function go_form_create_form()
}
add_action('admin_post_go_form_create_form', 'go_form_create_form');
function go_form_update_form()
{
go_form_admin_action('update_form');
if (isset($_POST['form_id']) && isset($_POST['form_name']) && !empty($_POST['form_name'])) {
global $wpdb;
$form_id = intval($_POST['form_id']);
$form_data = [
'name' => sanitize_text_field($_POST['form_name']),
'email' => isset($_POST['form_email']) ? sanitize_text_field($_POST['form_email']) : ''
];
$wpdb->update("{$wpdb->prefix}go_form_forms", $form_data, ['id' => $form_id]);
$redirect_url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $form_id, 'updated_form' => 1), admin_url('admin.php'));
wp_redirect($redirect_url);
exit;
}
$redirect_url = add_query_arg(array('page' => 'go-form-settings'), admin_url('admin.php'));
wp_redirect($redirect_url);
exit;
}
add_action('admin_post_go_form_update_form', 'go_form_update_form');
function go_form_delete_form()
{
go_form_admin_action('delete_form');
+25 -3
View File
@@ -7,6 +7,8 @@ if (isset($_GET['deleted']))
echo '<div class="notice notice-success"><p>Deleted!</p></div>';
if (isset($_GET['created']))
echo '<div class="notice notice-success"><p>Form created!</p></div>';
if (isset($_GET['updated_form']))
echo '<div class="notice notice-success"><p>Form updated!</p></div>';
if (isset($_GET['created_field']))
echo '<div class="notice notice-success"><p>Custom field created!</p></div>';
if (isset($_GET['updated_field']))
@@ -37,9 +39,24 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
$form = go_form_get_form_by_id($selected_form_id);
$form_name = $form ? $form->name : 'Unknown Form';
echo "<h3> $form_name</h3>";
// Form info and edit UI
if ($form) {
echo '<div style="margin-bottom:20px; padding:15px; background:#fff; border:1px solid #ddd; border-radius:4px;">';
echo '<form method="post" action="' . admin_url('admin-post.php') . '">';
echo wp_nonce_field('go_form_update_form_action', 'go_form_update_form_nonce', true, false);
echo '<input type="hidden" name="action" value="go_form_update_form">';
echo '<input type="hidden" name="form_id" value="' . esc_attr($selected_form_id) . '">';
echo '<table class="form-table">';
echo '<tr><th><label for="form_name">Form Name:</label></th><td><input type="text" name="form_name" id="form_name" value="' . esc_attr($form->name) . '" required></td></tr>';
echo '<tr><th><label for="form_email">Notification Email:</label></th><td><input type="email" name="form_email" id="form_email" value="' . esc_attr($form->email ?? '') . '" placeholder="Optional email for signup notifications"></td></tr>';
echo '</table>';
echo '<p class="submit"><input type="submit" class="button button-primary" value="Update Form"></p>';
echo '</form>';
echo '</div>';
}
echo '<div style="margin-bottom:15px; display: flex; flex-wrap: wrap; gap: 10px;">';
action_button('go_form_delete_form', 'Delete Form', 'Delete this form and ALL entries?', $selected_form_id);
action_button('go_form_export_csv', 'Export to CSV', 'Confirm Export', $selected_form_id);
action_button('go_form_export_pairgoth', 'Export to Pairgoth', 'Confirm Export', $selected_form_id);
@@ -225,6 +242,7 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
echo '<input type="hidden" name="action" value="go_form_create_form">';
echo '<table class="form-table">';
echo '<tr><th><label for="form_name">Form Name:</label></th><td><input type="text" name="form_name" id="form_name" required></td></tr>';
echo '<tr><th><label for="form_email">Notification Email:</label></th><td><input type="email" name="form_email" id="form_email" placeholder="Optional email for signup notifications"></td></tr>';
echo '</table>';
echo '<p class="submit"><input type="submit" class="button button-primary" value="Create Form"></p>';
echo '</form>';
@@ -234,7 +252,11 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
foreach ($forms as $f) {
$url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $f->id), admin_url('admin.php'));
echo '<li><a href="' . esc_url($url) . '">' . esc_html($f->name) . '</a> <span style="color:#888">(ID: ' . esc_html($f->id) . ')</span> - <small>Shortcode: <code>[go_form id=' . esc_html($f->id) . ']</code></small></li>';
echo '<li><a href="' . esc_url($url) . '">' . esc_html($f->name) . '</a> <span style="color:#888">(ID: ' . esc_html($f->id) . ')</span> - <small>Shortcode: <code>[go_form id=' . esc_html($f->id) . ']</code></small>';
if (!empty($f->email)) {
echo ' - <span style="color:#2271b1;">Email: ' . esc_html($f->email) . '</span>';
}
echo '</li>';
}
echo '</ul>';