WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to add form field to a WordPress widget dynamically. So if the user want to add another date to an event they can click a button to get more fields.

The question is: How do save newly created input fields to my database? Do i need to write a custom update function? Any tips?

This is how the widget looks: enter image description here

This is my php code for the widget (so far):

    class Spillelister extends WP_Widget {

    public function Spillelister() {

        $widget_options = array (
            'classname' => 'spillelister-widget',
            'description' => 'Widget for å illustrere spillelister.');

        parent::WP_Widget('spillelister_widget', 'Spilleplan', $widget_options);

    // The actual widget user interface
    public function widget($args, $instance) {

        extract( $args, EXTR_SKIP);
        $title = ( $instance['title'] ) ? $instance['title'] : 'Spilleplan';
        $body = ( $instance['body'] ) ? $instance['body'] : 'Ingen flere forestillinger';


            <?php echo $before_widget; ?>
            <?php echo $before_title . $title . $after_title; ?>
            <p><?php echo $body; ?></p>


    public function update() {


    public function form() {
        <div class="date_stamp">
            <label>Dato</label> <input type="text" class="datepicker">
            <label>Tid</label> <input type="text">
            <span class="remove">Remove</span>
            <span class="add">Add fields</span>



function spillelister_init() {
add_action('widgets_init', 'Spillelister_init');

Any tips, hints or answers are appreciated. :)

share|improve this question
I know I'm late, but I bumped into this thread and found an answer in another: wordpress.stackexchange.com/questions/94617/… The trick seems to be to pass values back as an array. – alexanderfilatov Jul 16 '14 at 13:58
@AlexanderFilatov Thank you! :) – Ole Henrik Skogstrøm Jul 16 '14 at 14:32
up vote 3 down vote accepted

Interesting Question!
I've never seen repeatable fields used in Widgets. Giving a full Answer would require too much work/time, so I'll give you links to the resources I know, and hopefully you'll make this work and share the solution with us ;)

All this examples deal with Meta Boxes, you'll need to copy the jQuery scripts and adapt the post_meta to the Widgets case.

share|improve this answer
Thank you! I'll check it out and give an answer if i work out how to solve this. If you or any one else find any more resources on this please do not hesitate to share it :) – Ole Henrik Skogstrøm Mar 3 '13 at 12:28
Never got to try this out, however if any one manages to build something like this please post your solution bellow. :) – Ole Henrik Skogstrøm May 1 '13 at 11:11

Your Answer


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.