0

I am creating a wp site for a sports team. On the main dashboard, I want to create a simple widget that will allow the admins to update the team's record. Then on a page template, I would like to echo out that content.

I COULD add custom fields using ACF to the page editor for the page in question, but I would like to get this on the dashboard for more visibility.

Here is what I have so far, I can get the form to show up, but I can't submit it to the db to store the data. In my functions.php (will move to site specific plug in later). Mainly my problems lie in the form action, and in the $control_callback

// Function that outputs the contents of the dashboard widget
function dashboard_widget_function( $post, $callback_args ) {
    echo '<form id="record" method="POST" action="//Should this point to a function or endpoint?"><input type="text" name="wins" id="wins" placeholder="wins">'
    .'<input type="text" name="losses" id="losses" placeholder="losses"><input type="submit" value="update"></form>';
}

function dashboard_widget_submit( $post, $callback_args ){
    //No idea what to do here
}
// Function used in the action hook
function add_dashboard_widgets() {
    wp_add_dashboard_widget('dashboard_widget', 'Stars Record', 'dashboard_widget_function', 'dashboard_widget_submit');
}

// Register the new dashboard widget with the 'wp_dashboard_setup' action
add_action('wp_dashboard_setup', 'add_dashboard_widgets' );
2

1 Answer 1

1

Here is a tutorial on submitting forms through dashboard widgets : http://www.wpexplorer.com/configurable-dashboard-widgets/

In the tutorial the author uses a single function for both displaying and updating the widget. What if you then use this approach and implement functionality similar to a save routine for custom meta boxes and custom fields to link the new meta data to a post/page id?

Could you try to add meta to a post/page or update existing meta of a post/page

add_post_meta( $post_id, $meta_key, $new_meta_value, true );
update_post_meta( $post_id, $meta_key, $new_meta_value );

I also noticed that he doesn't have the entire form markup present in his example so your form action could then be left blank

Hope it helps and that I'm not way off with what your trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.