You can’t. If you’re using the settings API correctly, here’s what happens when you try to save your options:
- Form posts to
options.php
- WordPress handles $_POST and runs
update_option
on your registered settings - Your sanitize callback from
register_setting
is applied - Any data that fails/you don’t return in your callback isn’t saved
- WordPress redirects back to your options page (
GET
)
Now you’re back on your options page, with the error message, but the data wasn’t written to the database and now $_POST
will be empty.
The only way I can see around it is to store the “incorrect” data in another option, inside your sanitize callback, for use on the returned page.
Related Posts:
- Settings API erases itself?
- Settings API – sanitize_callback is not called and it leads to an incorrect behavior
- How to know what submit button the user clicked?
- Multiple options pages validation for a plugin
- Prevent invalid or empty values from being saved to the database and retain the form field values upon error
- Settings API validation callback
- Flush rewrite rules on option update with Settings API
- Custom form in admin area, redirect in wrong page
- Validating custom fields before post save
- Front end post form validation
- Where this validating message come from?
- How to add custom regex validation to WPForms password field
- Code for front end validation for forms not working
- Whats the best practise on how to store json data from a custom settings page?
- How to save Checkbox-Options in Plugin Options Page
- Passing form data on submit
- Form Sanitization and Validation
- Displaying errors on the front end from my plugin
- Assigning input to variable
- How do I capture the selected option and pass in sending the registration form?
- Form validation on user profile edit
- What is & used for
- Reactjs – Form input validation
- How to define form action in JSF?
- Free or affordable OCR and ICR (handwriting recognition) SDK?
- What characters are allowed in an email address?
- How to include landing page with form submission?
- How to edit a user profile on the front end?
- How to display user registration form on front-end of the website?
- Add multiple custom fields to the general settings page
- “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
- How to pass arguments from add_settings_field() to the callback function?
- Is get_option function cached?
- How to pass variable to add_settings_section() callback?
- How to handle form submission?
- Contact form 7 select box different value-text than content-text in option [closed]
- What is an easy way to display a front-end user registration form?
- What are the advantages to the Settings API?
- Where to store plugin settings fields
- Add error message on password protected page
- How should one implement add_settings_error on custom menu pages?
- WordPress Settings API, Implementing Tabs On Custom Menu Page
- Difference between Option_Group and Option_Name in Register_Settings
- What’s the best method for emptying an option created with the Settings API?
- Settings API – easiest way of validating checkboxes?
- how to set from address according to the form input email address for wp_mail()?
- How to get current url in contact form 7
- Is wp_nonce_field vulnerable if you know the action name?
- Settings API – creating reusable form elements?
- add static page to reading settings for custom post type
- Settings API – changing add_settings_field() output?
- How to pass on Google Adwords gclid variable to other pages
- How to display an admin notice after updating plugin settings?
- using update_user_meta in form to set and get custom meta
- Best way to create multi-step form with data saved to user account for later updating?
- register_setting() vs add_option()
- Settings API – save an array of options as one setting (array_push?)
- User registration problem in WordPress
- Validate an option array
- Creating a contact form without a plugin [closed]
- How should I use register_setting, add_settings_section, & add_settings_field in my plugin’s options page?
- How to submit data from HTML form?
- Custom plugin settings: clicking “save changes” does not display success message
- what is the meaning of settings_fields()
- Custom Registration Template/Page
- show image in mail contact form 7 [closed]
- Setting ‘autoload’ to ‘no’ with Settings API
- Add Settings to Custom Post Type
- Can I verify nonce which was generated on a different WP site?
- How to Save Different Settings Options Using Settings API and/or the Theme Optimizer
- Submitting post to database then redirecting to paypal
- Serialized settings in rest api
- Can’t output do_settings_sections . Can’t understand why
- Registration form labels – add asterisk
- Autocomplete for taxonomy input boxes on a front end form
- Sending form data via PHPMailer – How to action PHP script from a form
- How to create and retrieve data from a special registration form?
- Why won’t register_setting() create a setting?
- Contact form 7 Dynamic text – placeholder on GET field
- how to handle forms in multiple pages?
- Settings API – how to update multiple options manually?
- set_query_var doesn’t seem to work on init hook
- Possible to add another setting to ‘Front page displays’ setting for Custom Post Type
- Setting the uploads directory
- How to send multipart form data to WordPress endpoint
- need to add attach thumbnail from my form
- Wp_mail Returning False on Server
- Single callback with multiple setting fields
- recommended practice for form submission
- Placeholders in Jetpack Contact Form [closed]
- Settings API – how to update options manually?
- Cannot update my options using wp_ajax
- How to update selective options on plugin settings page
- Built-in data validation function for URLs
- $_POST empty on submit (same code, same form submits normally on local server)
- Gravity Forms skip form if already filled out using cookie?
- Loading scripts & styles from a meta box callback function
- Checkbox won’t check when label is clicked
- how can I detect that option value has changed?
- One comment per user per post