WordPress PHP plugin – Settings page error

Your form is not including any additional parameters. $_SERVER['PHP_SELF'] is only the file name, not the ?page=job-board/adduser.php part. The script is going precisely where you are telling it to go.

You need to alter your form to push those values though. You need to include that GET component into the action attribute.

But give your page a proper slug instead of using __FILE__. Something like:

add_options_page('Plugin Admin Options', 'JobBoard Settings', 'manage_options','jobboard-settings', 'JobBoard_options_page');

That way, it will always have the same “location” on the backend.

Then use <form method="post" action="<?php echo admin_url('options-general.php?page=jobboard-settings'); ?>"/> instead of that $_SERVER mess.

And you really should be using Core functionality where possible, such as $wpdb.

Per information from comments below, and further edits to the question, you are trying to submit the form to a .php file named adduser.php located in your plugin folder (I assume) by telling the application to look at options-general.php?page=jobboard-settings/adduser.php. You can’t do that. WordPress doesn’t know where to find that file. That page parameter isn’t a file path. It the slug you used to register the page, and you didn’t register a page with that slug. You should be able to load the file by using the actual path– something like wp-content/plugins/pluginname/adduser.php but you have to jump through hoops to get WordPress functions working, and that is the wrong way to do it.

You could create a new page with add_options_page or add_submenu_page but I doubt you want another page. Just use the page you have. Submit the form to itself and process it inside the add_options_page('Plugin Admin Options', 'JobBoard Settings', 'manage_options','jobboard-settings callback or on one of these hooks— for example, settings_page_jobboard-settings.

Leave a Comment