0

I'm stumped as to why my code isn't working. I've done POSTS a million times, but this time it just doesn't seem to work.

My form:

<form method="post" name="form" id="form" enctype="text/plain" action="../posts/">
    <fieldset id="inputs" style="text-align: center;">
        <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
    </fieldset>
</form>

My PHP code for retrieval:

if(isset($_POST['password'])){
    echo "success";
}
else{
    echo "fail";
}

I get "fail" every time. What am I doing wrong? I just cant see it.

pedrum golriz
  • 513
  • 8
  • 27

3 Answers3

3

Remove enctype="text/plain" and check like

<form method="post" name="form" id="form" action="../posts/">
    <fieldset id="inputs" style="text-align: center;">
        <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
    </fieldset>
</form>

enctype defines how the data should be formatted before sending. the two correct formats are application/x-www-form-urlencoded (which essentially sends things as key=valye&anotherkey=anothervalue, with http headers) and multipart/form-data (which splits each key up into a distinct section of data). text/plain means nothing should be done - its behaviour is essentially undefined between browsers, and was only ever used for automated email forms in the days before spam.

GautamD31
  • 28,552
  • 10
  • 64
  • 85
1

Remove enctype="text/plain" from the form it will submit.

<form method="post" name="form" id="form"  action="../posts/">
    <fieldset id="inputs" style="text-align: center;">
        <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
    </fieldset>
</form>
Balaji Kandasamy
  • 4,446
  • 10
  • 40
  • 58
0

I agreed with @Gautam3164..You just remove enctype="text/plain" and check it out

<form method="post" name="form" id="form" enctype="text/plain" action="../posts/">
    <fieldset id="inputs" style="text-align: center;">
        <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
    </fieldset>
</form>

and change into

 <form method="post" name="form" id="form"  action="../posts/">
        <fieldset id="inputs" style="text-align: center;">
            <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
        </fieldset>
    </form>

and also refer this FIDDLE

VIVEK-MDU
  • 2,483
  • 3
  • 36
  • 63