Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I really hope I've got a simple issue in front of me here, as it's sort of driving me up a wall.

Short story: submitting a simple form on the front end of the site results in a 302 Found redirect, totally stripping the $_POST data in the process.

Scenario:

  • Create a page in the admin called Edit
  • Create a custom template file (ie, my-edit-template.php) and apply it to Edit

my-edit-template.php:

<?php
/**
 * Template Name: My Edit Template
 */

if ($_POST['action']) {
var_dump($_POST);
} 

get_header(); ?>

<form action="" method="post">
    <input name="my-ornery-field" value="">
    <input type="submit" value="submit">
    <input type="hidden" id="action" name="action" value="update-profile">
</form>

<?php get_footer(); ?>

Now, when I submit the form, I get two requests to the same page, first, the POST, with the form data intact, and second, a GET (status code 200), obviously stripped of the $_POST global, or anything useful to me.

I'm sure this is a total oversight, but I'm at a loss; utterly confused.

I've tried:

  • All plugins disabled
  • Flushing rewrites back to basic defaults
  • POSTing via Javascript/XHR

Help?

I'm sorry if the details are sparse, I'm sort of in class right now, but I'll follow-up with anything else relevant, later.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

This question is pretty old but the only one that popped out for this kind of problem. I had it this night, spend almost 4 hours hitting myself against the wall - disabling plugins, commenting code here and there (and this is a large multisite project with lots of custom functionality and frontend forms, custom urls and templates etc.). That was a pain...

I will just leave it here. Maybe it will save someone couple of hours.

"When building custom frontend forms, always prepend your input/select/etc names with your custom prefix."

When you forget about this and start naming fields to fit your global naming convention, you can create a select which shows your custom taxonomy and name it the same as a custom taxonomy is named itself. When you hit "Submit", WordPress receives your $_POST data, parses it, "understands" this name as its registered $query_var and transforms the request, adding this $query_var. Of course it results in a redirect, clearing your $_POST data and preventing form from doing what it supposed to do.

share|improve this answer
    
+1 You're awesome for adding a solution to an old, seemingly rare issue. The future thanks you, I'm sure. –  tksb Oct 7 at 18:08
    
Thanks :) I wished this problem (WordPress getting $query_vars not only from GET, but from POST as well) was described somewhere on Codex or somewhere else. That would save me a lot of time and neurons. Hope this will help someone in future. BTW, this question was the only relevant search result in Google. Seems the problem is really rare. And thanks to Otto's comment I understood that my code is 100% fine, the problem lies somewhere else. After only 10 minutes of debugging I figured everything out and fixed it. –  Ihor - paspar2.com Oct 8 at 14:49

There's nothing wrong with that code. I just did it on a local install and it worked fine, exactly how you'd expect.

Check for conflicting plugins.

share|improve this answer
    
That's part of why this is so irritating, the code is just fine. I'm just hoping for some insight into possible causes, I guess. –  tksb Apr 15 '11 at 19:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.