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?
- Search WordPress using static html page
- How to execute html code inside php?
- WordPress function and string as variable?
- Create a WordPress shortcode using PHP [duplicate]
- How to pass a PHP $_GET variable and fetch/output it?
- Creating WordPress Shortcode with Variable
- Apply class to every third list item? [duplicate]
- Where is this function’s callback getting its arguments from?
- persist a variable set in header.php all the way down to footer.php
- Can a page contain php code?
- How to send form data from WordPress (Meta Box) to an OData service?
- Get access to variable from previous pageview, excluding ajax-calls
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- WordPress shortcode returns the data before
- Shortcode to embed Edit Account form not working
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Form Submission Not Working In Custom Theme
- Insert page content into another page with a changed variable
- Pass Variables or Variable Place-Holder from Editor to PHP
- How to access or parse key/values that have “string”
- 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]
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- javascript variable to wordpress php variable
- How to display success message correctly and delete it when the page is refreshed
- Using admin-post.php for admin form but it directs me to admin-post.php white screen
- Why does my user not get added to the database on custom registration?
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- How to add post meta in while loop?
- How to reference PHP in Javascript
- How to set cookies
- Store and Change Session variable – PHP SESSION VARIABLE
- Overide Variable in Child Theme
- PHP Contact form
- Get wp_current_user_id using PHP and MySQL
- echo var into wp_query
- how can I include some custom variable from functions.php?
- Adding Additional Variables on Menus Page
- form built dynamically with php, not submitting
- Dynamically adding filters
- PHP- Why is my contact form keep showing it is invalid? [closed]
- Simple php in wordpress widget [closed]
- Search only working on front page (index) , not working on other pages
- form $_post action value gets truncated after it passes through two forms
- ‘global’ not working in wordpress?
- Pass important values server-side when processing form
- 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?
- Adding data to custom wordpress database table
- Make a page (url) not cacheable [closed]
- Php file that doesn’t recognize wordpress functions
- Front end file upload returning wrong attachment url
- WordPressUser Submission Form
- Display multi-select box choices in a bullet list [closed]
- Page Options Saving But Not Updating In Backend
- What should I write in the post action of this front end post form?
- PHP variables in a post?
- Custom forms with HTML
- Testing a Form’s Zipcode Field with Regular Expressions to Determine WordPress Page Behaviour
- WordPress is removing query variables like page, p from the URL of a custom static page
- Contact form – problem with displaying message about sent mail
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- 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
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- $_POST returning empty values
- How to check a variable Changes
- Trying to update Woocommerce meta values
- How to send custom form submissions to WordPress Database?
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Custom PHP form needs refresh to load page correctly
- Define global custom post
- Form from within a page
- Hide payment method based on user role AND minimum cart value
- I want it to detect the duplicate comment and give a warning on the same page
- Updating user meta adds string count to value?
- PHP multiple forms, same page, isset($_POST[]) not working?
- I want to retrieve the email or username data entered for password reset, but failed. how can I do it?
- 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
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- Best way to use variables in multiple functions?
- Trying to add some custom text into WordPress Post title via function.php
- Confuse between forms and tables
- wordpress contact form messages not sending although it saying they were sent successfully with this php code
- How to create a widget with a populated dropdown?
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- Store user form submitted information in post type
- Implement jQuery Smart wizard
- Using a PHP form, get the page title or any other element in the sent e-mail