summaryrefslogtreecommitdiffstats
path: root/includes/view-helpers/class-giglogadmin-venueform.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/view-helpers/class-giglogadmin-venueform.php')
-rw-r--r--includes/view-helpers/class-giglogadmin-venueform.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/includes/view-helpers/class-giglogadmin-venueform.php b/includes/view-helpers/class-giglogadmin-venueform.php
new file mode 100644
index 0000000..f837d73
--- /dev/null
+++ b/includes/view-helpers/class-giglogadmin-venueform.php
@@ -0,0 +1,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>';
+ }
+ }
+ }
+}