5

I am using the Codex example to build a custom widget. The specific example seems to be working fine until you click configure and change options values. After you click submit, changes are not saved. Is anyone having the same problem with the specific example? I am trying to build a custom widget using this as an example.

6
  • Ok fixed. In widget-config.php there is no check if the form has been submitted, so every time you load configuration it updates with empty values or keeps default ones. Add this check if (!empty($_POST)) before updating options values and display stored value of number-input. <input type="text" name="number" value="<?php echo self::get_dashboard_widget_option(self::wid, 'example_number'); ?>" />*
    – RRG
    Jun 17, 2013 at 12:45
  • Please add that comment as a real answer in the "Answer" box below and mark it "Accepted".
    – s_ha_dum
    Jun 17, 2013 at 12:55
  • I tried but I can't...I don't have that much reputation to do that.
    – RRG
    Jun 17, 2013 at 12:58
  • 1
  • 1
    Ok. You are running into that timer. Got it. @RRG : now you have >10
    – s_ha_dum
    Jun 17, 2013 at 13:22

1 Answer 1

2

Solution pulled from OP.

Ok fixed. In widget-config.php there is no check if the form has been submitted, so every time you load configuration it updates with empty values or keeps default ones. Add this check if (!empty($_POST)) before updating options values and display stored value of number-input:

<input type="text" name="number" value="<?php echo self::get_dashboard_widget_option(self::wid, 'example_number'); ?>" />
1
  • The examples in the codex should be updated with this fix.
    – j08691
    Sep 13, 2015 at 2:19

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.