WordPress.org

Ready to get started?Download WordPress

Forums

Set form action to self/same page form is on (10 posts)

  1. jeremyduffy
    Member
    Posted 6 years ago #

    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.

  2. jeremyduffy
    Member
    Posted 6 years ago #

    Nevermind, I ended up using an AJAX solution to the problem so I didn't have to worry about sending results to myself

  3. jeremyduffy
    Member
    Posted 6 years ago #

    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?

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

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

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

  5. jeremyduffy
    Member
    Posted 6 years ago #

    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 (jeremyduffy.com/postname).

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    ... 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.

  7. jeremyduffy
    Member
    Posted 6 years ago #

    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.

  8. jeremyduffy
    Member
    Posted 6 years ago #

    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.

  9. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  10. jeremyduffy
    Member
    Posted 5 years ago #

    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.

    Page:

    http://www.jeremyduffy.com/advanced-blog-search/

Topic Closed

This topic has been closed to new replies.

About this Topic