public static function handle_form_submission() { if ( ! current_user_can( 'manage_options' ) ) { return; } // Diagnostic: Uncomment the next 3 lines temporarily if you want to see exactly what POST variables arrive /* if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) { echo '
'; print_r( $_POST ); echo '
'; exit; } */ // Handle AJAX search requests early if ( isset( $_GET['action'] ) ) { global $wpdb; $action = sanitize_text_field( $_GET['action'] ); if ( $action === 'otg_search_players' ) { $term = '%' . sanitize_text_field( $_GET['q'] ?? '' ) . '%'; $results = $wpdb->get_results( $wpdb->prepare( "SELECT id, name, position, birthplace FROM otg_players WHERE name LIKE %s LIMIT 15", $term ) ); wp_send_json( $results ); } if ( $action === 'otg_search_games' ) { $term = '%' . sanitize_text_field( $_GET['q'] ?? '' ) . '%'; $results = $wpdb->get_results( $wpdb->prepare( "SELECT id, game_id, game_date, season, home_team_abbr, away_team_abbr FROM otg_rangers_games WHERE game_date LIKE %s OR game_id LIKE %s OR home_team_abbr LIKE %s OR away_team_abbr LIKE %s LIMIT 15", $term, $term, $term, $term ) ); wp_send_json( $results ); } } // Handle POST submissions on admin_init where headers are still clean if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_POST['otg_rangers_event_nonce'] ) ) { if ( ! wp_verify_nonce( $_POST['otg_rangers_event_nonce'], 'otg_rangers_event_nonce_action' ) ) { return; // Nonce failed validation } global $wpdb; $table_name = 'otg_rangers_events'; $form_action = sanitize_text_field( $_POST['otg_form_action'] ?? '' ); $search_year = sanitize_text_field( $_POST['search_year'] ?? '' ); $search_day = sanitize_text_field( $_POST['search_day'] ?? '' ); $current_url = admin_url( 'admin.php?page=rangers-events' ); if ( $search_year ) $current_url = add_query_arg( 'search_year', $search_year, $current_url ); if ( $search_day ) $current_url = add_query_arg( 'search_day', $search_day, $current_url ); // Handle Delete if ( $form_action === 'delete' ) { $event_id = intval( $_POST['event_id'] ?? 0 ); if ( $event_id > 0 ) { $deleted = $wpdb->delete( $table_name, [ 'event_id' => $event_id ], [ '%d' ] ); if ( $deleted !== false ) { $current_url = add_query_arg( 'message', 'deleted', $current_url ); } else { $current_url = add_query_arg( 'error', 'delete_fail', $current_url ); } } wp_safe_redirect( $current_url ); exit; } // Handle Add / Update if ( $form_action === 'save' ) { $event_id = intval( $_POST['event_id'] ?? 0 ); $event_date = sanitize_text_field( $_POST['event_date'] ?? '' ); $title = sanitize_text_field( $_POST['title'] ?? '' ); $excerpt = sanitize_textarea_field( $_POST['excerpt'] ?? '' ); $category = sanitize_text_field( $_POST['category'] ?? '' ); $related_player_id = !empty( $_POST['related_player_id'] ) ? intval( $_POST['related_player_id'] ) : null; $related_game_id = !empty( $_POST['related_game_id'] ) ? intval( $_POST['related_game_id'] ) : null; $you_tube_link = !empty( $_POST['you_tube_link'] ) ? esc_url_raw( $_POST['you_tube_link'] ) : null; if ( $event_date && $title ) { $data = [ 'event_date' => $event_date, 'title' => $title, 'excerpt' => $excerpt, 'category' => $category, 'related_player_id' => $related_player_id, 'related_game_id' => $related_game_id, 'you_tube_link' => $you_tube_link, ]; $format = [ '%s', '%s', '%s', '%s', '%d', '%d', '%s' ]; if ( $event_id > 0 ) { $updated = $wpdb->update( $table_name, $data, [ 'event_id' => $event_id ], $format, [ '%d' ] ); if ( $updated !== false ) { $current_url = add_query_arg( 'message', 'updated', $current_url ); } else { $current_url = add_query_arg( 'error', 'update_fail', $current_url ); } } else { $inserted = $wpdb->insert( $table_name, $data, $format ); if ( $inserted ) { $current_url = add_query_arg( 'message', 'added', $current_url ); } else { $current_url = add_query_arg( 'error', 'add_fail', $current_url ); } } } else { $current_url = add_query_arg( 'error', 'missing_fields', $current_url ); } wp_safe_redirect( $current_url ); exit; } } } Gerard Gallant – Activity – OutsideTheGarden Boards – Page 36
SEPTEMBER
«
Sat
30
Sun
31
Mon
1
Tue
2
Wed
3
Thu
4
Fri
5
»
Gerard Gallant
Gerard Gallant
Group: Registered
Joined: 2023-10-19
Team MVP
1
Follow
The first line twin losers looking sharp again. 🙄

In forum Where Smit Hits The Fan

2 years ago
Is Robertson that bad he can't make it as the 9th damn?

In forum Where Smit Hits The Fan

2 years ago
Yesssss

In forum Where Smit Hits The Fan

2 years ago
They're equally as dumb as "fans" at msg And the wimpy...

In forum Where Smit Hits The Fan

2 years ago
Schneider n miller trying to assist on the game tying goal. ...

In forum Where Smit Hits The Fan

2 years ago
Will be interested to see what they do the rest of this game...

In forum Where Smit Hits The Fan

2 years ago
The kreider turnover from being lazy was the game Then...

In forum Where Smit Hits The Fan

2 years ago
He is a player I've talked about with friends that would fit...

In forum Where Smit Hits The Fan

2 years ago
Recipe to lose 1. Let their top scorer score 2. Let...

In forum Where Smit Hits The Fan

2 years ago
Rangers clawed a PT out of it. Respectable

In forum Where Smit Hits The Fan

2 years ago
@fish Showcasing him for a trade 🤣...

In forum Where Smit Hits The Fan

2 years ago
Kreider and zibanejad won't step up. Lol Maloney...

In forum Where Smit Hits The Fan

2 years ago
Lol no ranger wanted to hit anyone or get the puck

In forum Where Smit Hits The Fan

2 years ago
Lindgren sharp tonight

In forum Where Smit Hits The Fan

2 years ago
Trouba with the sweet pass to Matthews in the slot

In forum Where Smit Hits The Fan

2 years ago
Page 36 / 44