Nate
Nate

Reputation: 28384

Form data not POSTing to another page

I am struggling with a problem I have never had before. I have a form on a page that submits its data via POST to another page, but the data is not arriving at the other page. If I make action="" and then var_dump() at the top of the page with the form, the POST data prints out fine, BUT if I make action="http://localhost/dir/" and put var_dump() at the top of that page, then array empty prints out. What on earth might be causing this behavior? How do I debug this? I'm lost.

Form:

<form id="form" method="post" action="http://localhost/dir">
    <input type="hidden" name="id" value="19">
    <select style="width: 60px;" name="number">
        <option value="1">1</option><option value="2">2</option><option value="4">4</option>
    </select>

    <input type="submit" class="input_submit" value="Submit" id="submitButton">
</form>

Code at top of index.php file:

var_dump($_POST);die();

Upvotes: 0

Views: 1538

Answers (2)

asprin
asprin

Reputation: 9823

Try

<form id="form" method="post" action="../dir/index.php">
    <input type="hidden" name="id" value="19">
    <select style="width: 60px;" name="number">
        <option value="1">1</option><option value="2">2</option><option value="4">4</option>
    </select>

    <input type="submit" class="input_submit" value="Submit" id="submitButton">
</form>

assuming 'dir' directory is out side the directory of the file which contains this form.

Upvotes: 1

itsols
itsols

Reputation: 5582

To post data to a page that is on a different directory, use a relative path.

For example, consider this. DirSub1 and DirSub2 are in the same level and they're both within DirTop.

  • DirTop
  • DirSub1
  • DirSub2

Now, if your form is in the directory DirSub1 and you need to post it to x.php in DirSub2, you write the action property like this:

action="../DirSub2/x.php"

Hope this solves your problem.

Upvotes: 1

Related Questions