• Hello

    Hope I’m in the right area here.

    I am coding a theme options page

    after setting up some options (in array) for different theme options user can modify, I also added the proper validation and form to render those options

    Thats all perfectly working

    I the used this to save my options:

    //the relevant "save" section of my code
    case "close":
    $i++;
    ?>
    <input name="save<?php echo $i; ?>" type="hidden" />
        <?php submit_button() ?>//that button displays after each section
    </div><!--#section_body-->
    </div><!--#section_wrap-->
    
    <?php break;
    }
    }
    ?>
    
    <input type="hidden" name="action" value="save" />
    <?php submit_button( 'Save All Options' ) ?>//after ALL sections
    </form>
    
    <form method="post">
    
    <input type="hidden" name="action" value="reset" />
        <div class="warning">
        <?php echo _e('Warning! Next Step Resets ALL options!', 'minmax3'); ?>//After ALL sections
        </div>
    <?php submit_button( 'Reset All Options' ); ?>
    </form>
    <br/>
    </div><!--#options-wrap-->

    OK, now, I would like my “Save Button” to save only a section at once
    => let’s say section A has a button and section B too
    If i now hit on save (doesn’t matter which one) ALL sections get saved

    thats cool for the last button that says “Save ALL Options”
    But not for the button after each section that says “Save Changes” (default WP value)

    So now, do we have any API to follow here?
    I couldn’t find any in this case.

    could anyone give me a example?

    🙂

    => you know what would be very fancy?
    the relevant section being shortly highlighted
    (in whatever color)
    once user saves one single section)
    🙂 🙂

    I thank everybody who gives me a input here!
    ( i assume I must pass another variable in the save button, something like a “if” is section, save related section…) ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Well, you could break up your settings into several forms, each with its own save button. Then if you wanted to save all at once, you’d need some javascript function to submit the forms via script, one by one. Additionally, the entire page would reload for every save button click, potentially losing edits made in other sections. Not good.

    The alternative would be to use AJAX to save individual sections of a single form. The save buttons would simply invoke some save section script. Only the save all button would actually submit the entire form. With AJAX, you don’t really need any save buttons at all. Each setting could be saved when that particular field is changed.

    AJAX is a bit too much to get into here, I’ll refer you to https://developer.ww.wp.xz.cn/plugins/javascript/
    This is just a landing page of sorts, the following 4 pages describe the AJAX process in detail.

    Thread Starter beda69

    (@beda69)

    hello

    thanks for te reply

    i see it can’t be done with simple php

    will look into that AJAX and post my findings here….

    tnx

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

The topic ‘save options sections one by one’ is closed to new replies.