3

I'm trying to implement a "publish" button from a custom post type metabox. Everything actually works fine if I either create a new button and manually call submit() or duplicate the regular submit buttons, except for one thing: if i change the title of the post, I always get the "Confirm Navigation" popup asking me if I want tstay or leave the page. It doesn't do this when using the regular "Update" button though, so there's gotta be a way to stop it, I just can't seem to get a handle on it.

Custom save button using a link:

<a href="#" id="saveChangesButton" class="button-primary alignright">Save</a>

// in ready()
$('#saveChangesButton').live('click', function() {
        $('#saveChangesButton').addClass('button-primary-disabled');
        $('#post').submit();
        return false;           
});

Custom save buttons trying to mimic the submitdiv's buttons:

<?php if ($_GET['action'] == 'edit') : ?>
    <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Save') ?>" />
    <input name="save" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="Update">

<?php else: ?>
    <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" />

    <input name="publish" type="submit" id="publish" class="button-primary" value="Publish" tabindex="5" accesskey="p">
<?php endif; ?>
  • Post some relevant code along with your questions, please. – soulseekah Oct 21 '11 at 5:54
  • added code samples. Either way I create the buttons, if I change the post's title, I get the "Confirm Navigation" dialog when trying to save. – flashape Oct 21 '11 at 17:46
  • Have you seen exactly how the publish link originally works? core.trac.wordpress.org/browser/tags/3.2.1/wp-admin/includes/…, I don't see how your code comes close to this. Are you creating those metaboxes with the add_meta_box() function? – soulseekah Oct 21 '11 at 18:41
  • All I wanted to do was submit the post from a secondary button, not recreate the entire process. I worked around the issue by disabling autosave for my custom post type and it works fine now. – flashape Oct 21 '11 at 19:48
2

You can stimulate click to Update post button like this.. Adding submit or update button to custom metabox?

<script>
jQuery('.metabox_submit').click(function(e) {
    e.preventDefault();
    jQuery('#publish').click();
});
</script>
<input type="submit" class="metabox_submit" value="Submit" />
  • that is actually what I wound up doing....way simpler. – flashape Apr 23 '12 at 18:47
  • This doesn't seem to publish a new post though, only update it. – Devin Walker Aug 10 '15 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.