• Hi,
    I’ve created a tab based options page for a WordPress theme I’m making, and it all works fine. However, it would be quite nice for the form to submit and stay on the same tab, as this could get quite annoying.

    There are two ways I’ve though of doing this:

    1. Store the tab name/id as a query string, and then read it and open that tab on page load. The problem with this is it requires me to edit JS, which I’m not good at. Also, I’m not sure how to add the tab ID as a query string when the form is submitted.
    2. Stop the page refreshing, presumably using AJAX. Not really sure how to do this, but presumably I’d use jQuery to submit the form.

    Any help is much appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • If I understand you, you have to do this with Javascript (with or without jQuery).

    Thread Starter CodeBotics

    (@codebotics)

    jQuery => Javascript ?? I found this great jQuery Form Plugin: https://www.malsup.com/jquery/form/

    Which I called using:

    function form_no_refresh() {
    	?>
    	<script src="https://malsup.github.com/jquery.form.js"></script>
    	    <script>
            // wait for the DOM to be loaded
            jQuery(document).ready(function() {
                // bind 'myForm' and provide a simple callback function
                jQuery('#adminform').ajaxForm(function() {
                    alert("Thank you for your comment!");
                });
            });
    		</script>
    	<?php
    }
    add_action('admin_head', 'form_no_refresh');

    It’s not ideal for two reasons:

    1. It relies on this existing: https://malsup.github.com/jquery.form.js. I could download it locally though.
    2. It loads the script on every admin page, but I can fix this by checking if the page is the page I’m expecting then calling the function.

    But, it works, so I’m keeping it!

    I responded that you needed to use Javascript not because I don’t know what jQuery is but because you seemed to be trying to avoid Javascript, which you say you aren’t good at.

    Thread Starter CodeBotics

    (@codebotics)

    Ah, sorry I didn’t make the link! You’re right, Javascript is needed no matter what by the looks of it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Submitting Custom Options without Refresh’ is closed to new replies.