September 27, 2009
Posting A Form to A WordPress Page
I develop quite a few sites in WordPress. Being that many of these sites are not “blogs” and need to behave like a traditional, static website, I’ve come across and worked through several obscure and (understandably) poorly documented issues and quirks in WordPress.
This is one of those stories.
I had a page template with a simple contact form that was posting to # (itself):
<form name="contactform" method="post" action="#"> <input name="name" /> <input name="email" /> <input name="phone" /> <textarea name="comment"></textarea> <input type="submit" name="submit" /> </form>
Looked great, but when I submitted the form, instead of reloading the page with the form posted, WordPress would display the 404 error page. Looking at the address bar, the URL was identical (except with a # at the end), and if I reloaded the page without reposting the form data, the unsubmitted page would load fine. I was both baffled and maddened.
As a last, desperate resort, I decided to change the names of the form fields, after which it worked perfectly. Being that I’d worked on that issue for an hour, it was a frustrating relief.
I didn’t know this at the time, but WordPress uses POST variables (the same kind that you pass when you submit a form) in the secret hocus pocus that goes on in the background as a page loads. And my POST variables were conflicting with them.
So, I just added “form” in front of all the field names, and it was golden:
<form name="contactform" method="post" action="#"> <input name="formname" /> <input name="formemail" /> <input name="formphone" /> <textarea name="formcomment"></textarea> <input type="submit" name="submit" /> </form>
So the moral of the story is this:
If you are posting a custom form anywhere within WordPress, use very unique field names so that they don’t conflict with WordPress’ variables. Otherwise, when you submit the form, it will have errors displaying the page, and instead display the 404 error page.
I think I just saved you an hour.

Great… you saved me an hour.
Thanks..
Gr8 tip! Thanks ;)
I reckon you’ve saved me several hours – many thanks!
Great! Thanks, I was banging my head against my desk trying to get this contact form working!
Thank you! This was starting to drive me nuts, thanks for sharing
Thanks a lot, this saved me a lot of time and frustration.
This worked for me! Thank you, thank you, thank you!
Thanks for posting, solved the problem I was having.
Unfortunately I wasted about an hour trying to figure it out on my own. Fortunately, I think you saved me a few more, plus some hair.
Thanks.
Thanks a lot. Perfect!
Thanks Caleb. Your solution worked a treat!
Thanks for that – I’m sure this will come in handy in the future.
I’m kind of pissed the solution was so easy, but very grateful that the error is fixed. Thank you very much!
Just repeating what everyone else said, but I wasted so much time with this stupid thing. Thank you!!
You are my saviour!!! I feel like an idiot for changing the fields to ‘name’ and ‘email’ instead of ‘your_name’ and ‘your_email’ just because I thought they “looked cleaner”… won’t do that again! Thank you!
Excellent, thanks!
Thank you for starting this excellent thread. I’ve been looking info like this.
My hero! I thank you for that hour you saved! :)
This worked for me also. Thanks.
Thanks Mr. Smart.
I wasted about an hour on this then found your solution, THANKYOU so much!!!
Thank you so much for pointing me to this! Now (after trying different things for an hour) my form works like a charm.
Wow,
You have just saved me more than just an hour. I would have never thought of this.
Worked a charm.
Excellent tip, thanks saved me an hour def.
You are the greatest person in the world. I just spent an hour trying to figure out why my form was not working and then found this page and problem fixed.
THANK YOU!!!
Thank you very much! Saved me from pulling all my hair out!
unfortunately this is not the case. I tried this. My variable names are something like.. name_this_product_name_14 but still its not working.
But I am sure, atleast this is not the same name variable issue.
Thanks for that Caleb. My hybrid comment/contact form class was – guess what – *sharing the field names* across the forms. Just adding a unique prefix property to each subclass plus a tad more effort on the back end fixes it real good. 10/10.
I’ve Been Helped!
*thumbs up* definitely saved me 45 minutes! :)
Thank you so much! I think you just saved me half a lifetime! ;)
I wouldn’t have figured this one out on my own, I was thinking it was some kind of security feature of WP and I’d have to wade through a heap of other plugins. Thank you, thank you *worship* You saved me a good few hours.
You definitely saved me an hour. Thanks a lot, great post.
Thank you so much for this solution. It works a treat.
Can’t say you saved me an hour… I already used up three or four trying to figure this out. THANK YOU.
Thanks, man. You saved me an hour. ;)
Thanks you saved me….(hours)
OMIGOD. I DID spend hours, but you finally saved my sanity!!! THANKS!
Thank you so much for your post.
Thanks for this post man.. didn’t save me an hour, but at least now I know what’s going on..
Now, THAT’S WHAT I’M TALKING ABOUT!
You solved are a real baffler for me…thanks
the wordpress support community rocks.
You most definately just saved me an hour. I thought the reason it wasn’t posting the data was because wordpress redirects in the backend, therefore losing the data during file jumps on the server.
Thx a lot man
Thanks a lot man!! Your magic saved my life.
Really great… Problem resolved
Thanks! It was taking like forever for me to get the solution! Your article helped a lot.
thank you so much 4 your post..it really hepled me..:)
Thank you a lot! You saved me an hour!
This is really helpful – thanks
Wish I had read this before I wasted an hour…