0

I can't find the error. Why doesn't receive my result page the POST variables from my form? I do always get an empty array with my var_dump. Can anyone here help me out? The code is so simple that I don't know what further possible error sources I could remove. If I switch to GET it works instantly.

I'm testing this on my Debian old stable system which I have been using for such things for years now without issues. (But it doesn't work on my externally hosted web server either.)

My form.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="device-width, initial-scale=1">
    <title>Form page</title>
</head>
<body>
    <form name="test" action="result.php" enctype="text/plain" method="post">
        <select name="chose">
            <option value="1">one</option>
            <option value="2">two</option>
            <option value="3">three</option>
        </select>
        <input type="submit" value="save">
    </form>
</body>
</html>

My result.php:

<?php
var_dump($_POST);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="device-width, initial-scale=1">
    <title>Result page</title>
</head>
<body>
    <h1>Result</h1>
    <p><a href="form.php">return</a></p>
</body>
</html>

I think I'm getting crazy here. I must overlook something breathtakingly simple.

  • Oh, yes. I discovered it just after I asked the question. (Unfortunately I didn't get this idea the hours before I posted my question.) – Onsemeliot Feb 13 '22 at 20:52

1 Answers1

3

enctype="text/plain" is designed to present form data in a human readable format for debugging. It is not machine processable (e.g. you can't distinguish between new lines in data and new lines between entries).

Remove that.

(I don't consider it very good for debugging anyway, the dev tools built into browsers can display URL encoded data in a human readable format)

PHP will automatically populate $_POST when data is encoded as application/x-www-form-urlencoded (the default for forms) or multipart/form-data (a chunkier format that supports file uploads).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335