Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a plugin and would like to add a dashboard widget with a custom form. In this form, users should be able to edit a list of strings (add, edit and remove items). Is there a WordPress API to do something like that? I already know how to add a dashboard widget, but I don't know how to make a form in a dashboard widget / how to process the data.

The only thing I can think of is to redirect the user to my options page - there must be a neater way. Is there any?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

There are two options to use forms in a dashboard widget:

  1. Use the parameter control_callback. See the Codex

    wp_add_dashboard_widget(
        'my_id',            // $widget_id 
        'my_name',          // $widget_name 
        'my_render_widget', // $callback 
        'my_control'        // $control_callback
    );
    function my_control()
    {
        // print some form elements, WordPress will handle the <form> tag.
    }
    
  2. If you want to use a form in the main display handler, set the form action to admin-post.php and add a callback function for a custom action there. Example. When you are done processing the form redirect back to the dashboard.

share|improve this answer
    
Great! It works, thanks! I'll accept your answer after a while unless there's a better answer. –  Camil Staps Jun 21 '13 at 9:20
    
(With 'it' I mean the second approach) –  Camil Staps Jun 21 '13 at 9:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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