Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 111
Form Fields
ОглавлениеWordPress has a special table class just for forms called form‐table
. This class is used on all WordPress Dashboard forms, including every Settings page. This is a useful class when creating any type of options in your plugin.
<div class="wrap"> <?php screen_icon( 'plugins' ); ?> <h2>My Plugin</h2> <form method="POST" action=""> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="fname">First Name</label></th> <td><input maxlength="45" size="25" name="fname"/></td> </tr> <tr valign="top"> <th scope="row"><label for="lname">Last Name</label></th> <td><input id="lname" maxlength="45" size="25" name="lname"/></td> </tr> <tr valign="top"> <th scope="row"><label for="color">Favorite Color</label></th> <td> <select name="color"> <option value="orange">Orange</option> <option value="black">Black</option> </select> </td> </tr> <tr valign="top"> <th scope="row"><label for="featured">Featured?</label></th> <td><input type="checkbox" name="favorite"/></td> </tr> <tr valign="top"> <th scope="row"><label for="gender">Gender</label></th> <td> <input type="radio" name="gender" value="male"/> Male <input type="radio" name="gender" value="female"/> Female </td> </tr> <tr valign="top"> <th scope="row"><label for="bio">Bio</label></th> <td><textarea name="bio"></textarea></td> </tr> <tr valign="top"> <td> <input type="submit" name="save" value="Save Options" class="button-primary"/> <input type="submit" name="reset" value="Reset" class="button-secondary"/> </td> </tr> </table> </form> </div>
Using the form‐table
can give your options a familiar look to your plugin users. This makes for a better user experience, as shown in Figure 3‐13.
FIGURE 3‐13: WordPress‐like options