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
- Free or affordable OCR and ICR (handwriting recognition) SDK?
- What characters are allowed in an email address?
- What is an easy way to display a front-end user registration form?
- What are the advantages to the Settings API?
- How to get current url in contact form 7
- How to display an admin notice after updating plugin settings?
- Best way to create multi-step form with data saved to user account for later updating?
- Custom plugin settings: clicking “save changes” does not display success message
- what is the meaning of settings_fields()
- Add Settings to Custom Post Type
- Can’t output do_settings_sections . Can’t understand why
- Checkbox won’t check when label is clicked
- how can I detect that option value has changed?
- How to display some settings for super admin user only using Settings API
- Performance of several get_option() calls
- add function to saving change on Options Pages
- Is there a limit to the number of options you can store in one settings field of wp_options?
- How to validate register settings array
- How can i add validation to this login form with out it redirecting to the wp-login.php page
- How do I setup nested repeatable option fields?
- Getting settings saved two times in settings page with tab
- Performing a POST action on homepage goes to posts page
- How to get bool with `get_option()` when already registered setting with type `boolean`
- Form Processing
- Form validation in WordPress Admin Panel
- Remove Internal Style Sheet if no Value Provided?
- Customize reset password form redirect problem
- creating form for wp_remote_post
- Settings API – Separating PHP and HTML
- How do I use the info submitted in a form to create a form reception page? (like “thank you {firstName}”) [closed]
- Show admin notice on incorrect value on form field
- Can you disable the mail function in contact form 7 [closed]
- Adding a new user from the front end
- Embed interactive pdf
- Grab values from the query string to fill in hidden fields in ninja forms [closed]
- Make editor required for post from frontend
- WordPress tabindex Order
- Is there a WordPress form plugin that can easily be configured for Google Analytics goals?
- How to code auto-retry for API call
- How to check form input against PHP variable?
- How to validate my form
- how to insert textbox value in existing database table in wordpress?
- Update WP option by plugin
- Is it possible to pass variables to WordPress externally?
- Theme settings Page: Settings Api vs Update_Options
- Dashboard Contact Form
- How can I receive uploaded attach file as a Google drive link [closed]
- Exporting a form to a CSV file does not work in WordPress but it does in PHP
- How to redirect with success message in wordpress admin panel?
- WordPress – Users with contact form on profile
- How to stop iFrame form from reloading on mobile?
- Multiple checkbox doesn’t work in wordpress settings api
- I’m needing to figure out how to create a page that user could create a “task” and it be selectable on a form
- contact form and WP loop
- Timezone dropdown in form
- Unexpected token admin.php
- display a message if get form is empty
- Unable to delete option
- Adding a different domain to existing WordPress site
- .html form added to a page
- Sending email via function in page or setting up the action properly in another page
- add_settings_error on validating plugin options API
- Remove active cursor from form field
- import excel form into wordpress
- Custom setting field value not working inside add_action init hook
- Custom Contact Form Not Sending (but not giving error)
- Auto Select Child categories on Multiple Dropdown – Jquery
- Can I use add_option for a plugin categories and how?
- Custom form on front page redirects on error page
- IE 9 Clears Form Fields
- jQuery Live Form Validation in WordPress
- How to get formidable entry ID by post ID? [closed]
- Calling custom PHP from a HTML form post action gives 404 error
- How to add a checkbox with categories of entries to the form Contact Form 7 WordPress
- Conditional Logic for the Input Mask in Caldera Forms [closed]
- How to manage to submit WPForms at our webpage
- Adding default quicktags to textarea
- How can I get lost form data back? [closed]
- Forminator + Hubspot Workflows