Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

POST variables won't arrive … why?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading