I've created a dashboard widget in my functions.php file. I want to have it be able to update some stuff in the database upon form submittal. According to the codex documentation, I should be handling my post submissions with the 4th argument of wp_add_dashboard_widget(), $control_callback.
So I've created my handler function and included it in my functions.php file. When I have my form submit, nothing happens. I thought about it for a minute, and then I hooked the callback function to wp_dashboard_setup with add_action(); My call back function now runs, but its doing so regardless of whether I pass the control_callback function to wp_add_dashboard_widget() making me feel like my solution is kind of hacky.
Am I doing this wrong and is there a better way to do tthis? Also, is my form supposed to submit anywhere fancy or can it just submit right back to where its drawn?
Heres my full code:
function custom_dashboard_widget_coach() {
echo "
<p><strong>Finalize Game</strong></p>
<form method='post'>
<div class='team_class_wrap'>
<label>Class</label>
<select name='team' id='team'>
<option value='5a'>5A</option>
<option value='4a'>4A</option>
<option value='3a'>3A</option>
<option value='2a'>2A</option>
</select>
</div>
<input type='submit' value='Report Game Result' />
</form>
";
}
function custom_dashboard_widget_coach_handle()
{
var_dump($_POST);exit;
}
function add_custom_dashboard_widget_coach() {
wp_add_dashboard_widget('custom_dashboard_widget_coach', 'My Team', 'custom_dashboard_widget_coach', 'custom_dashboard_widget_coach_handle');
}
add_action('wp_dashboard_setup', 'custom_dashboard_widget_coach_handle');
add_action('wp_dashboard_setup', 'add_custom_dashboard_widget_coach');