submit_button

Home » Functions » submit_button

Function Name: submit_button

The submit_button() function is a WordPress core function that allows developers to create a submit button for forms in the WordPress admin panel. This function is particularly useful for plugin and theme developers who want to create custom forms and settings pages.

The submit_button() function generates a button with the label "Save Changes" by default, but developers can change the label by passing an argument to the function. The function also includes a hidden input field called "_wpnonce" that helps protect against CSRF attacks.

Example usage code:

<?php
// Create a custom form with a submit button
function my_custom_form() {
  ?>
  <form method="POST" action="">
    <label for="name">Name:</label>
    <input type="text" name="name" id="name">
    <?php
      // Add the submit button
      submit_button('Save Name');
    ?>
  </form>
  <?php
}

// Display the custom form
add_action('admin_menu', function() {
  add_menu_page('My Custom Form', 'My Custom Form', 'manage_options', 'my-custom-form', 'my_custom_form');
});

In this example, we create a custom form with a single input field for the user’s name and a submit button labeled "Save Name". We use the submit_button() function to generate the submit button. When the user submits the form, the data is sent to the URL specified in the form’s "action" attribute.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.