• Resolved David Gewirtz

    (@dgewirtz)


    So now that we know how to delete a Save button, is there a way to have multiple save buttons? This is useful on long forms where only a section of the form needs to be updated and saved. For example, there might be “Save Host Options,” “Save Tweaks,” “Save PayPal Settings,” etc.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’d check out some of the things over at https://github.com/CMB2/CMB2/wiki/Tips-&-Tricks specifically around appending custom content that you could use to potentially append extra button markup. I know I’ve seen javascript used to add new stuff as well for some things I’ve been a part of utilizing CMB2.

    Thread Starter David Gewirtz

    (@dgewirtz)

    Thanks. That got me started, but this seems to work. I tried adding a custom field type, but ran into a snag easily modifying the extra padding in the surrounding field divs. So I just made a function that blasts a named action button onto the page. If there’s a more elegant approach, I’m all ears.

    // Adds custom action button to form
    // $name is the the text displayed in the button
    // $id is the unique id of the action button
    
    function cmb2_add_action_button($section_options, $name, $id) {
        $section_options->add_field(array(
            'name'    => esc_attr($name),
            'id'      => esc_attr($id),
            'render_row_cb' => 'cmb2_row_callback_for_action_button',
        ));
    }
    
    function cmb2_row_callback_for_action_button( $field_args, $field ) {
        $button_name = $field->args["name"];
        $button_id   = $field->args["id"];
        ?>
        <div class="action-button-row">
            <p class="submit"><input type="submit" name="<?php echo esc_attr($button_id); ?>"
                                                           id="<?php echo esc_attr($button_id); ?>"
                                                           class="button button-primary"
                                                           value="<?php echo esc_attr($button_name); ?>"></p>
        </div>
        <?php
    }
    
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Nothing I know of off the top of my head, but I welcome anyone else who may have ideas for this that are better than what I’ve suggested.

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

The topic ‘Multiple Save buttons per metabox?’ is closed to new replies.