Support » Fixing WordPress » Set form action to self/same page form is on

  • Normally, a PHP_SELF would work for a form like this, but with the various ways that permalinks can be set up, what do I do here? I want the form to send the data back to itself. Currently, I have the form in a page template and this is the only page that has it.

    My offline machine can’t use pretty permalinks, but my online site does. How do I get it to work for both? I don’t want to have to test for and preserve a “page_id” value IN CASE the page is using standard links style unless I absolutely have to.

    There should be a clean way to do this.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Nevermind, I ended up using an AJAX solution to the problem so I didn’t have to worry about sending results to myself

    Nevermind again. Ajax is buggy and people can’t store search results in the URL this way. So how do you send form results to the page you’re on again?

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Set the action of the form to a blank value. Then the form posts back to the current page.

    <form action="" method="POST">

    I’m pretty sure I tried that. Keep in mind that I want this to work for all types of permalinks if possible. My offline development environment doesn’t work with pretty permalinks so it uses the index.php?varshere style while my main site does (

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    … I’m not entirely sure what you’re asking then, because that is definitely the correct answer. What type of permalinks you use have nothing to do with it.

    A blank action on a form makes the form submit to the current URL. This is a matter of HTML, not permalinks or any specific WordPress coding.

    I’ll try it again and post the results of what happens. Of course, that won’t be until later tonight when I’m on my home machine.

    Didn’t work. On my home system, all the form variables are there, but not the page. I can make a variable in the form preserve the page id I suppose, but it’s a hack. I was hoping for something cleaner.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    I guess I’m really not understanding the problem here. What exactly is not working about it?

    Because I use that same solution all the time in my own webapps. It works perfectly fine. I know it works, so you’re clearly trying to do something else than what you’ve been saying you’re doing, or something like that.

    I think I was expecting something that wasn’t reasonable. I added a form element to preserve the page_id variable for pages that use standard permalinks. It’s working perfectly so far and should to the foreseeable future so long as wordpress doesn’t change the variable name.

    Thanks for the help though! At least it’s working now.


Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Set form action to self/same page form is on’ is closed to new replies.