• Resolved biohazardapparel

    (@biohazardapparel)


    I’m missing a fundamental concept from the Create a Form tutorial:

    All the form fields in the tutorial are static. Once you set them, they stay that way until the user manually changes them. This makes for a great “settings” form, but I need a form that allows the user to input some data for a query, and then reset the fields back to their blank state so the form can be used for another query.

    Specifically, I’m trying to do this:

    1. Dropdown field for “order_id”
    2. User selects order_id and hits submit
    3. If order_id has a value, get some data about the order and display it in a “text_area”
    4. User validates information by clicking a second submit button (different field name)
    5. Form data is cleared

    All the fields are defined within the “load_{page_name}” function, as shown in the tutorial.

    Everything works except step 5, because I can’t figure out how to clear the form data! Once a given field is set, it remains set every time you reload the page; the form re-populates itself with all the data from the previous Submit.

    https://ww.wp.xz.cn/plugins/admin-page-framework/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter biohazardapparel

    (@biohazardapparel)

    P.S. My initial assumption is that there is something I can do using the removeSettingFields() method, but if so, I can’t figure out where to put it. I’ve tried putting it in after_{page_slug} and after_ClassName, but all the data in the getOption fields is still there, even after running something like this:

    `public function do_after_ClassName() {
    $this->removeSettingFields( ‘my_field_name’ );
    }’

    Plugin Author miunosoft

    (@miunosoft)

    Hi,

    What I would suggest is to create hidden tabs.

    1. Create a main page with
    – an in-page tab that displays an initial form.
    – hidden in-page tabs that display a form derived from the previous values.

    2. Redirect the user to the hidden tab in the validation callback method with exit( wp_redirect( $url ) ); depending on the submitted form values in the initial form.

    To clear the stored options, you can use the
    validation_{...} filter and return an empty array from the callback.

    To force the form fields to display initial field values, you can use the
    options_{instantiated class name} filter and return an empty array from the callback.

    Let me know if you need example code.

    Thread Starter biohazardapparel

    (@biohazardapparel)

    Oh I would LOVE me some example code 🙂 I’m doing pretty well so far, considering I’m not a WP developer, but this project has been stretching my limits. I’ll take all the help I can get 🙂

    Plugin Author miunosoft

    (@miunosoft)

    Here you go.
    https://gist.github.com/michaeluno/8849b9c84768c817ce22

    Let me know if you get any issue.

    Thread Starter biohazardapparel

    (@biohazardapparel)

    Very cool of you, thank you! It’s going to take me some time to read thru this, but I’ll post my results here when done. P.S. I contacted you via your website earlier today 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Reset Form Field Data / Remove Unused getOption() Data’ is closed to new replies.