So I'm trying to create my first admin form for a calendar/scheduling plugin I want to make. The form looks good, the javascript issues are behind me and now I can't seem to get the $_POST data which is driving me crazy. I have tried a bunch of different ways (as you can probably tell by all of the commented out code) to no avail. In my current attempt I'm reposting to the page and testing for the submit button being clicked which does seem to pass through in the $_POST...just not the eventTitle.
I've been all over the interwb looking at examples but none of them seem to work for me so I'm obviously missing some crucial piece of information. Any help would be greatly appreciated!
<?php
/**
* Created by PhpStorm.
* User: eric.downey
* Date: 10/31/2014
* Time: 1:42 PM
*/
function sdCalendarAdmintInit()
{
// add_action ( 'admin_action_SaveEvent', 'processSaveEvent' );
}
function processSaveEvent()
{
global $wpdb;
// Make sure this person can actually save this info...
if ( !current_user_can( 'manage_options' ) ) wp_die ('Not allowed');
$title = $_POST['eventTitle'];
$tableName = $wpdb->prefix . sdEventTable;
$wpdb->insert(
$tableName,
array(
'title' => $title,
'startTime' => current_time ('mysql'),
'endTime' => current_time ('mysql'),
'created' => current_time ('mysql'),
));
// Redirect to the configuration form that was processed.
wp_redirect( $_SERVER['HTTP_REFERER'] );
//wp_redirect ( add_query_arg( 'page', 'sdCalendar_menu_settings', admin_url('CalendarSaveEvent.php') ) );
exit();
}
function SDCalendarConfig()
{
if( isset($_POST['Submit']) && $_POST['Submit'] == 'Save Event' ) {
global $wpdb;
print_r($_POST);
echo "<br />";
print_r($_GET);
$eventTitle = (isset($_POST["eventTitle"]) ? "It's set" : "It's not set");
$tableName = $wpdb->prefix . sdEventTable;
$wpdb->insert(
$tableName,
array(
'title' => $eventTitle,
'startTime' => current_time ('mysql'),
'endTime' => current_time ('mysql'),
'created' => current_time ('mysql'),
));
}
$options = get_option( 'sdCalendar_options' );
?>
<div class="wrap">
<h2>Smith & Dow Calendar v<?php echo $options[ 'version' ] ?> Configuration</h2>
<h3>Add/Edit an Event</h3>
<form method="post" action='<?php esc_url( $_SERVER['REQUEST_URI'] ) ?>'> <!--<?php echo admin_url( 'admin.php' ); ?>"-->
<input type="hidden" name="action" value="SaveEvent" />
<table id="addEditEventTable">
<tr>
<td>
<label for="eventTitle" class="required">Title</label>
</td>
<td>
<input type="text" id="eventTitle" > <!--class="k-textbox" placeholder="Event title" required validationMessage="Please enter an event title" -->
</td>
</tr>
<tr>
<td>
<label for="startDateTimePicker">Start date/time</label>
</td>
<td>
<input id="startDateTimePicker" >
</td>
</tr>
<tr>
<td>
<label for="endDateTimePicker">End date/time</label>
</td>
<td>
<input id="endDateTimePicker" >
</td>
</tr>
<tr>
<td>
<label for="allday">All day?</label>
</td>
<td>
<input type="checkbox" id="allDay" />
</td>
</tr>
<tr>
<td>
<label for="holiday">Holiday?</label>
</td>
<td>
<input type="checkbox" id="holiday" />
</td>
</tr>
<tr>
<td>
<label for="cancelOnHoliday">Cancel on holidays?</label>
</td>
<td>
<input type="checkbox" id="cancelOnHoliday" />
</td>
</tr>
<tr>
<td>
<label for="location">Location</label>
</td>
<td>
<input type="text" id="location" >
</td>
</tr>
<tr>
<td>
<label for="category">Category</label>
</td>
<td>
<select id="category" placeholder="Select category...">
<option>Open gaming</option>
<option>Tournament</option>
</select>
</td>
</tr>
<tr>
<td valign="top">
<label for="description">Description</label>
</td>
<td>
<textarea id="description" rows="5" cols="15" style="width:475px;height:220px">
</textarea>
</td>
</tr>
<tr>
<td valign="top"><label>Recurrence</label></td>
<td>
<div id="forecast">
<div id="tabstrip">
<ul>
<li class="k-state-active">
None
</li>
<li>
Daily
</li>
<li>
Weekly
</li>
<li>
Monthly
</li>
<li>
Yearly
</li>
</ul>
<div>
<div class="recurrence" id="noOccurrence">
<div style="margin: 10px auto 10px; width: 440px;">
This event only occurs once.
</div>
</div>
</div>
<div>
<div class="recurrence" id="dailyOccurrence">
<div style="width: 440px;">
<table>
<tr>
<td>
<input type="radio" name="dailyType" value="everyXDays">Every <input id="dayNumberDaily" type="number" value="1" min="1" max="364" style="width: 70px;" /> day(s)
</td>
</tr>
<tr>
<td>
<input type="radio" name="dailyType" value="everyDay">Every day
</td>
</tr>
</table>
</div>
</div>
</div>
<div>
<div class="recurrence" id="weeklyOccurrence">
<div style="width: 440px;">
Recur every <input id="weekNumberWeekly" type="number" value="1" min="1" max="364" style="width: 70px;" /> week(s) on:<br />
<table>
<tr>
<td><input type="checkbox" id="sunday" /> Sunday</td>
<td><input type="checkbox" id="monday" /> Monday</td>
<td><input type="checkbox" id="tuesday" /> Tuesday</td>
<td><input type="checkbox" id="wednesday" /> Wednesday</td>
</tr>
<tr>
<td><input type="checkbox" id="thursday" /> Thursday</td>
<td><input type="checkbox" id="friday" /> Friday</td>
<td><input type="checkbox" id="saturday" /> Saturday</td>
</tr>
</table>
</div>
</div>
</div>
<div>
<div class="recurrence" id="monthlyOccurrence">
<div style="width: 440px;">
<table>
<tr>
<td>
<input type="radio" name="monthlyType" value="dayNumber"> Day
<input id="dayNumberMonthly" type="number" value="1" min="1" max="31" style="width: 60px;" />
of every
<input id="monthNumberMonthly" type="number" value="1" min="1" max="12" style="width: 60px;" />
month(s)
</td>
</tr>
<tr>
<td>
<input type="radio" name="monthlyType" value="weekNumber">The
<select id="weekNumber" >
<option>first</option>
<option>second</option>
<option>third</option>
<option>fourth</option>
</select>
<select id="dayName" >
<option>Sunday</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
</select>
of every
<input id="monthNumber2Monthly" type="number" value="1" min="1" max="12" style="width: 60px;" />
month(s)
</td>
</tr>
</table>
</div>
</div>
</div>
<div>
<div class="recurrence" id="yearlyOccurrence">
<div style="width: 440px;">
<table
<tr>
<td>
Recur every <input id="yearNumberYearly" type="number" value="1" min="1" max="99" style="width: 60px;" /> year(s)
</td>
</tr>
<tr>
<td>
<input type="radio" name="yearlyType" value="specifyMonthDay">On:
<select id="monthNameYearly" >
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<input id="dayNumberYearly" type="number" value="1" min="1" max="31" style="width: 60px;" />
</td>
</tr>
<tr>
<td>
<input type="radio" name="yearlyType" value="specifyWeekMonth">On the:
<select id="weekNumberYearly" >
<option>first</option>
<option>second</option>
<option>third</option>
<option>fourth</option>
</select>
<select id="dayNameYearly" >
<option>Sunday</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
</select>
of
<select id="monthNameYearly" >
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td colspan="2">
<input class="k-button" type="submit" name="Submit" value="Save Event" />
</td>
</tr>
</table>
</form>
</div>
<style scoped>
#addEditEventTable td { padding: 10px; }
.k-textbox {
width: 11.8em;
}
label {
display: inline-block;
width: 100px;
text-align: right;
}
.required {
font-weight: bold;
}
.accept, .status {
padding-left: 90px;
}
.valid {
color: green;
}
.invalid {
color: red;
}
span.k-tooltip {
margin-left: 6px;
}
</style>
<script>
//$(document).ready(function () {
jQuery(document).ready(function ($) {
// Daily tab
$("#dayNumberDaily").kendoNumericTextBox({ format: "0"});
// Weekly tab
$("#weekNumberWeekly").kendoNumericTextBox({ format: "0"});
// Monthly tab
$("#dayNumberMonthy").kendoNumericTextBox({ format: "0"});
$("#monthNumberMonthy").kendoNumericTextBox({ format: "0"});
$("#monthNumber2Monthy").kendoNumericTextBox({ format: "0"});
// Yearly tab
$("#yearNumberYearly").kendoNumericTextBox({ format: "0"});
// create DateTimePicker from input HTML element
$("#startDateTimePicker").kendoDateTimePicker({
value:new Date()
});
$("#endDateTimePicker").kendoDateTimePicker({
value:new Date()
});
$("#description").kendoEditor();
$("#category").kendoComboBox();
$("#tabstrip").kendoTabStrip({
animation: {
open: {
effects: "fadeIn"
}
}
});
/* var validator = $("#title").kendoValidator().data("kendoValidator"),
status = $(".status");
$("button").click(function() {
if (validator.validate()) {
status.text("Event title accepted.")
.removeClass("invalid")
.addClass("valid");
} else {
status.text("An event title is required.")
.removeClass("valid")
.addClass("invalid");
}
});*/
});
</script>
<?php
}