$_SERVER["PHP_SELF"] will NOT get you the current URL in WordPress, but will return /index.php (as that’s the PHP script that is being executed).
WordPress then doesn’t know what to do with the data that has been submitted and decides to redirect to the home page.
If you want to submit to the current page, you can just leave the action attribute empty, e.g.
<form action="" method="POST">
What you are doing will work, but it’s not really the WordPress way of doing things, you might want to look into developing a plugin and using AJAX (you don’t have to have a plugin for that, you can simply define actions in your theme’s functions.php).
Related Posts:
- How to fix ‘Notice: Undefined index:’ in PHP form action
- add_filter the_content str_replace after shortcode
- Genesis – Customize search form
- How to insert PHP code in a WordPress Post
- Has anyone tried putting PHP ActiveRecord on WordPress?
- Handling error states with admin_post
- Creating wordpress user registration form
- submit the form to same page
- Ajax form submit within a Post Metabox
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- Upload Image in a WordPress page using PHP
- Custom Form Processing Issue
- My form action url is being prepended with a directory that does not exists
- Custom profile field with birthday. Troubles with
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- Post + form + action + results on the same page
- How to pre populate a form field with a link of a current user’s author profile?
- Why Won’t My Inputs in a form with a Get method work together?
- Input data from email form not going to JSON file
- How to get the value of input hidden html from text editor to custom page template?
- Contact form won’t submit
- wp_mail file attachment not being placed in upload folder?
- Databases – Submitting data from inputs to database [closed]
- How to show a ‘correct’ message after submit a form?
- db converts decimal number wrong
- WordPress admin-ajax.php 400 bad request
- Ajax contact form return 0
- “operation successful” message
- Search WordPress using static html page
- How to put a form with php code into a variable or shortcode?
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- WordPress shortcode returns the data before
- Shortcode to embed Edit Account form not working
- Form Submission Not Working In Custom Theme
- Capture form data in one function and use it in another function (same file)
- 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
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- Get wp_current_user_id using PHP and MySQL
- Adding Additional Variables on Menus Page
- form built dynamically with php, not submitting
- PHP- Why is my contact form keep showing it is invalid? [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
- 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
- Front end file upload returning wrong attachment url
- WordPressUser Submission Form
- Page Options Saving But Not Updating In Backend
- What should I write in the post action of this front end post form?
- Custom forms with HTML
- Contact form – problem with displaying message about sent mail
- Cascading dropdown select search based on Parent Page & Child Page
- HTML Form Question
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Trying to update Woocommerce meta values
- Form from within a 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?
- “Class Not Found” in HTML Form Target PHP File that contains the class
- 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?
- 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
- form submission reverts to index.php template
- 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
- Adding action item to admin users table and sending email
- If input field has value Require another field – PHP
- 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
- Trying to display user meta by “name” – not by “ID”
- Styling admin page rows in order of importance (checkboxes)
- Display default WordPress login/registration form into a modal window
- Force string into signup form
- custom contact form no longer working (because of 3.2?)
- Data inserted in database, but ajax calls error function
- upload images on front by user using form
- Correct Syntax for uploading files to custom directory in WordPress
- ajax form function error
- Send foreach $_post method to contact form 7 [closed]
- php inside HTML via shortcode? [closed]
- Use HTML Form Data in PHP Function – WordPress Admin Page
- Contact form with dynamic dropdown and filter
- Custom form that stores data in mysql database
- Putting form result in my database
- Bulk data save in custom table
- How to create a form that display license key (and email it to user) after the user enter their email and 10 digit code?
- Automatically populating a date parameter within a shortcode
- How can I process a form submission from an HTTP POST request?