I have a plugin that has tabs in the admin with a form on the first tab. The second tab is hidden until information is saved into the form on the first tab. I want the button in the form to redirect the user to the second tab onclick after the options are saved. Using wp_safe_redirect and getting an error - Cannot modify header information. Have tried all the necessary things to make this go away, like removing spaces before the opening and closing PHP statement, adding ob_start, and ob_end_flush. No go. Have messed around with this for a couple weeks. Tried JavaScript and a few other tricks that haven't worked. Please help!
Here's my code below:
//checks for active tab and replaces key with the related settings key. Uses the plugin_options_tabs method to render the tabs.
function plugin_options_page() {
echo '<link type="text/css" rel="stylesheet" href="' .plugins_url( 'css/spreview.css' , (__FILE__) ). '" />';
$tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $this->locate_listing_key;
if ($tab == $this->locate_listing_key) {
?>
<div class="sprwrap">
<?php $this->plugin_options_tabs(); ?>
<form method="post" action="options.php">
<?php wp_nonce_field( 'update-options' ); ?>
<?php settings_fields( $tab ); ?>
<?php do_settings_sections( $tab ); ?>
<input type="submit" name="submit" value="<?php _e('Find It') ?>" class="button-primary" />
<?php $myadminurl = admin_url();
$redirect_to = $myadminurl . 'admin.php?page=spr_plugin_options&tab=select_listing'; ?>
</form>
<?php ob_start();
global $wp_version;
if ( version_compare( $wp_version, '3.4.0', '>=' ) ) {
if ((isset($_GET['updated']) && $_GET['updated'] == 'true') || (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true')) {
$location = empty($redirect_to) ? get_redirect_link() : $redirect_to;
wp_safe_redirect($location);
exit;
} //end of updated true
}
ob_end_flush(); ?>
</div>
<div class="sprwrapright">
<?php spreview_sidebar_one() ?>
</div><div class="clear"></div>
<?php } else if ($tab == $this->select_listing_key) {
?>
<div class="sprwrap">
<?php $this->plugin_options_tabs(); ?>
<?php //settings_fields( $tab ); ?>
<?php do_settings_sections( $tab ); ?>
<?php include 'superpages-reviews-listings.php'; ?>
</div>
<div class="sprwrapright">
<?php spreview_sidebar_two() ?>
</div><div class="clear"></div>
<?php }
}