0

I'm struggling to figure out why my plugin's settings form is redirecting to the homepage. What I expect is, the settings page should reload after the form is submitted.

Should the form redirect to the homepage? Why is this form directing to the homepage? What am I doing wrong? (I expect I've missed something obvious.)

class BlogPlugin {
    public static function run() {
        add_action( 'admin_menu', array( __CLASS__, 'add_menu' ) );
        add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
    }

    public static function add_menu() {
        add_options_page( 'Blog Plugin Settings', 'Blog Plugin', 'edit_pages', 'blog_plugin_settings', array( __CLASS__, 'render_settings_page' ), false, 62 );
    }

    public static function register_settings() {
        register_setting( 'bp_blog_plugin', 'bp_input' );
    }

    public static function render_settings_page() {

        add_settings_section(
            'blog_plugin_settings_section',
            '',
            '',
            'blog_plugin_settings'
        );

        add_settings_field(
            'bp_input',
            'An input',
            array( __CLASS__ , 'input_view' ),
            'blog_plugin_settings',
            'blog_plugin_settings_section'         
        );

        ?>
        <div class="wrap">
            <h1>Blog Plugin Settings</h1>
            <form action="post" action="options.php">
                <?php 
                    settings_fields( 'bp_blog_plugin' );
                    do_settings_sections( 'blog_plugin_settings' );
                    submit_button();
                ?>
            </form>
        </div>
        <?php
    }

    public static function input_view(){
        echo('<input type="text" name="bp_input">');
    }
}

BlogPlugin::run();

Edit

I have removed the reference to the non-existent function and have confirmed that the plugin runs on my installation. (The form still redirects to the homepage.)

1
  • There are several references to non-existing functions in your code, so we can not test it. Could you post a sample code that we can use to reproduce the issue?
    – cybmeta
    Commented May 28, 2018 at 8:11

1 Answer 1

1

Having had a good night's sleep, I see the typo is glaringly obvious.

I have:

<form action="post" action="options.php">

It should be:

<form method="post" action="options.php">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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