settings_fields()WP 2.7.0

Output nonce, action, and option_page fields for a settings page.

No Hooks.

Return

null. Nothing (null).

Usage

settings_fields( $option_group );
$option_group(string) (required)
A settings group name. This should match the group name used in register_setting().

Examples

0

#1 settings_fields() displays hidden form fields, so it must be inside the form tag:

<form method="POST" action="options.php">
	<?php 
	// page slug on which the form is displayed, 
	// same as the group name ($option_group) in the options API
	settings_fields( 'my-page' );   

	// page slug on which the form is displayed
	do_settings_sections( 'my-page' );  
	submit_button();
	?>
</form>
0

#2 More examples

For other examples of use, see the examples on the API settings page.

Changelog

Since 2.7.0 Introduced.

settings_fields() code WP 6.5.2

function settings_fields( $option_group ) {
	echo "<input type='hidden' name='option_page' value='" . esc_attr( $option_group ) . "' />";
	echo '<input type="hidden" name="action" value="update" />';
	wp_nonce_field( "$option_group-options" );
}