summaryrefslogtreecommitdiffstats
path: root/includes/view-helpers/class-giglogadmin-venueform.php
blob: f837d73c3d0169cdb8a54582b0428e31f405144d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
 * Class to handle the form for adding venues.
 *
 * @package giglogadmin
 *
 * SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
 * SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

if ( ! class_exists( 'GiglogAdmin_VenueForm' ) ) {
    class GiglogAdmin_VenueForm {

        public function render() : string {
            return '<div class="venueform">'
                . '<p><strong>VENUE DETAILS</strong></p>'
                . '<form method="POST" action="" class="venue">'
                . '  <fieldset>'
                . wp_nonce_field( 'edit-venue', 'nonce' )
                . '    <div class="field venue_name_field">'
                . '      <label for="venue">Venue Name:</label>'
                . '      <input type="text" id="venuename" name="venuename">'
                . '    </div>'
                . '    <div class="field venue_city_field">'
                . '      <label for="venuecity">Venue City:</label>'
                . '      <input type="text" id="venuecity" name="venuecity">'
                . '    </div>'
                . '    <div class="actions">'
                . '      <input type="submit" name="newvenue" value="Create New Venue">'
                . '    </div>'
                . '  <fieldset>'
                . '</form>'
                . '</div>';
        }

        static function update() : void {
            if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'edit-venue' ) ) {
                header( "{$_SERVER['SERVER_PROTOCOL']} 403 Forbidden" );
                wp_die( 'CSRF validation failed.', 403 );
            }

            if ( empty( $_POST['venuename'] ) || empty( $_POST['venuecity'] ) ) {
                echo '<script language="javascript">alert("You are missing a value, venue was not created"); </script>';
            } else {
                GiglogAdmin_Venue::create( $_POST['venuename'], $_POST['venuecity'] );
                echo '<script language="javascript">alert("Yey, venue created"); </script>';
            }
        }
    }
}