The code you posted has a major flaw*: it mixes HTML and PHP without properly setting them apart. This code chunk has a PHP function call followed by an HTML string, but since there’s nothing telling the file that it should be treated as HTML, the parser says “Hey, <form
isn’t anything I recognize. I’m outta here!”
* That nearly everyone gets hit by at some time when using PHP and HTML. 🙂
The offending code here is
// adding the page to menu
add_menu_page('Theme Options', 'Theme Options', 'manage_options', 'rm-options', 'rm_display_options_page');
// form to display options
<form method="post" action="options.php">
<?php
settings_fields('rm_theme_options'); // options name
do_settings_sections('rm-options'); // page
submit_button();
?>
</form>
You have a couple of options here, one is to tell PHP to echo
the HTML like this:
// adding the page to menu
add_menu_page('Theme Options', 'Theme Options', 'manage_options', 'rm-options', 'rm_display_options_page');
// form to display options
echo '<form method="post" action="options.php">';
settings_fields('rm_theme_options'); // options name
do_settings_sections('rm-options'); // page
submit_button();
echo '</form>';
Another is to bracket out the PHP parts so the HTML isn’t parsed by PHP:
// adding the page to menu
add_menu_page('Theme Options', 'Theme Options', 'manage_options', 'rm-options', 'rm_display_options_page');
// form to display options
?>
<form method="post" action="options.php">
<?php
settings_fields('rm_theme_options'); // options name
do_settings_sections('rm-options'); // page
submit_button();
?>
</form>
<?php
...
* Update *
There’s a bit of string concatenation that I can’t quite wrap my eyes around, so I’ve changed that here to make it easier for me to grasp. It may help with fixing any errors, too.
It’s also best practice to escape attributes in your HTML, so I updated that line to include those functions.
echo "<input type="text" id='$id' name="rm_theme_options[$id]" value="" . esc_attr( $options[$id] ) . "" />';