I'm adding for the first time a wordpress dashboard widget. I'm creating a simple form to give the user the ability to send support request directly from wp dashboard. I'm not sure if all the code is working, during a test, I've noticed that the form will not submit the mail message. Can anyone help me?
function uptheme_support_dashboard_widgets()
{
global $wp_meta_boxes;
wp_add_dashboard_widget('custom_help_widget', 'Premium Ticket System', 'custom_dashboard_help');
}
function custom_dashboard_help()
{
$current_theme = wp_get_theme( 'uptheme-panel' );
?>
<p><?php _e('Hi! you are using the custom theme '. esc_html($current_theme) ); ?></p>
<p><?php _e('Use the form to request support for your theme.'); ?></p>
<form method="POST">
<p><?php _e('Email'); ?></p>
<input type="text" class="widefat" name="email" id="email" placeholder="" />
<p><?php _e('Request type'); ?></p>
<select name="support_ticket_type">
<option value=""><?php _e('Support request'); ?></option>
<option value=""><?php _e('Modification request'); ?></option>
</select>
<p><?php _e('Message'); ?></p>
<textarea class="widefat" name="support_message"></textarea>
<input type="hidden" name="action" value="submit_support_ticket">
<?php wp_nonce_field( 'submit_support_ticket', 'support_ticket_hash' ); ?>
<button class="btn-primary" type="submit" class=""><?php _e('Invia'); ?></button>
</form>
<small><?php _e('Theme powered by'); ?><a href="#"><?php _e('theme author'); ?></a></small>
<?php
}
add_action('wp_dashboard_setup', 'uptheme_support_dashboard_widgets');
function _submit_support_ticket()
{
if( isset($_POST['support_ticket_hash']) || ! wp_verify_nonce( $_POST['support_ticket_hash'], 'submit_support_ticket' ) ){
//echo '';
exit;
}
$email = $_POST['email'];
$subject = $_POST['support_ticket_type'];
$message = $_POST['support_message'];
$to = '[email protected]';
$headers[] = "From: <$email>";
wp_mail( $to, $subject, $message, $headers );
}
add_action( 'admin_post_submit_support_ticket', '_submit_support_ticket' );
action
? It should submit toadmin-post.php
..wp_ajax_
?isset($_POST['support_ticket_hash'])
should be! isset($_POST['support_ticket_hash'])
. Otherwise, the page would exit even if there was actually a valid nonce.wp_ajax_
, I'm not sure what you mean, but if you use that hook, then your AJAX request should be sent toadmin-ajax.php
. Theadmin_post_
hooks are for regular/non-AJAX form submissions, but their syntax is identical to thewp_ajax_
hooks.