filter_input
is the proper way to go. If it doesn’t return anything valid, it will return null
:
$myvar = filter_input( INPUT_POST, 'something', FILTER_SANITIZE_STRING );
if ( empty( $myvar ) ) {
// Do whatever you would have done for ! isset( $_POST['something'] )
}
// Use $myvar
filter_input
won’t throw any notices if the requested index isn’t found, so it’s like having isset
built-in to the function.
Edit: just be sure to use a FILTER_
to sanitize or validate, and note there are some gotchas that are documented in PHP’s documentation about these. For most general use-cases they should work fine, but always validate your user input appropriately once you have it (the same as you would when getting it directly from $_POST
).
Related Posts:
- Where to get information about array fields in $_REQUEST?
- Call global variable array() in woocommerce child/template
- How to modify a global variable in a function and use it on another function?
- How to put a form with php code into a variable or shortcode?
- global $product is empty string when passed into function
- Custom global variable not working in function
- How can one use variables in a template or template part without polluting the global scope?
- How to fix ‘Notice: Undefined index:’ in PHP form action
- Custom plugin: Trying to show saved data on frontend
- How to call a function only once (global variable scope)
- Pass a PHP variable to another file
- Genesis – Customize search form
- How to store the_title() into a variable to reutrn the value, not just echo it
- Create a global variable for use in all templates
- Has anyone tried putting PHP ActiveRecord on WordPress?
- Handling error states with admin_post
- On update to 3.04 site started recording accents as “á” and “á”, what to do?
- submit the form to same page
- Implement a multi-value input field where the number of entries is not limited
- JavaScript, best way to use data from the loop
- Locating Global Variables
- Pass PHP variable to JavaScript without inline JS
- Count the number of times the search form template gets included on a page
- woocommerce registration form with klaviyo(don’t work with current user)
- Custom Form Processing Issue
- get_term_link() returns correct – But illogical error-messages disturb
- Custom profile field with birthday. Troubles with
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to prevent XSS alter custom global javascript object & methods in WordPress
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Custom search results page not working with empty search
- Post + form + action + results on the same page
- Input data from email form not going to JSON file
- Search Query: how to construct a search string from two select elements?
- Databases – Submitting data from inputs to database [closed]
- How to show a ‘correct’ message after submit a form?
- db converts decimal number wrong
- Ajax contact form return 0
- “operation successful” message
- Search WordPress using static html page
- WordPress function and string as variable?
- Creating WordPress Shortcode with Variable
- Get access to variable from previous pageview, excluding ajax-calls
- Shortcode to embed Edit Account form not working
- Capture form data in one function and use it in another function (same file)
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- javascript variable to wordpress php variable
- Using admin-post.php for admin form but it directs me to admin-post.php white screen
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- form built dynamically with php, not submitting
- Search only working on front page (index) , not working on other pages
- WPDB secure custom form
- Adding attribute to the post.php form tag in wp-admin
- How to make blog post entries appear as input form instead of just text?
- Php file that doesn’t recognize wordpress functions
- Front end file upload returning wrong attachment url
- WordPressUser Submission Form
- Page Options Saving But Not Updating In Backend
- PHP variables in a post?
- Cascading dropdown select search based on Parent Page & Child Page
- HTML Form Question
- How to send a php var to jQuery Ajax call with two different file
- Unable to display multiple parameters from url by javascript through shortcodes
- Define global custom post
- Updating user meta adds string count to value?
- PHP multiple forms, same page, isset($_POST[]) not working?
- WordPress How do I pass a variable from one add_action to another?
- “Class Not Found” in HTML Form Target PHP File that contains the class
- Best way to use variables in multiple functions?
- Store user form submitted information in post type
- Implement jQuery Smart wizard
- How to change the value of a variable using input field?
- Javascript / PHP – closing the loop
- How do I stop my form from adding code to current page URL instead of re-directing. Been stuck for days
- Updating the database after parsing CSV document
- Creating wordpress user registration form
- Add class to all meta boxes for a custom post type
- If input field has value Require another field – PHP
- Passing parameter from the current URL to redirect to another url
- Pulling a variable into the wp_nav_menu function
- global $post inside plugin query messes up every new post page in wp-admin
- Submitting my form to the database and then redirecting to payment site
- Passing link parameter values to form
- Processing forms with php to wordpress database
- Post from front end form to post_meta
- Accessing values entered via form – try again
- Nonce fail after second submit attempt
- Editing Global Variables from Inside Functions
- Styling admin page rows in order of importance (checkboxes)
- how to add number value in front for variable [closed]
- Create and update Custom Cookie based on multiple GET and POST Values for first time visitors?
- WordPress $GLOBALS and PHP $GLOBALS
- Difference in Get Variable Location
- Data inserted in database, but ajax calls error function
- upload images on front by user using form
- ACF allow zero as a value
- Can’t get options with $data[‘variable’]
- Import and use a variable in additional settings of Contact Form 7 [closed]
- WP query with variables gives no result for specific user