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