1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

inputのdisabled属性とreadonly属性におけるPOST時の挙動の観察

Last updated at Posted at 2019-01-11

:beginner: 注:PHP初心者の記事です
もっといい解決方法があったら教えてください。

TL; DR

disable:POSTできない。
readonly:POSTできる。

記事に至るまでの紆余曲折

経緯

phpでフォームをつくる課題が出た。
確認画面から送信をする時、つまり2回目のPOSTで失敗。
大量のNotice: Undefined index:が。
var_dump($_POST)で中身をぶちまけるとarray(0){}
要するにPOSTできていない、ということであった。

PHPのせいにしてみたり、送信ボタンのタグのせいにしてみたり、formタグも疑ったりしたが、
結局inputの属性が悪いことが分かった。

解決

当方、確認画面で結果表示にinputタグをそのまま使って楽をしようとしていたのだが、
その時にdisable属性を思い出してしまったのが不幸にも黒塗りの高(略。

8h潰した戦犯(お名前欄)
お名前:<input name="name" value="<?php echo $_POST["name"]; ?>" disable>

大体はこんなことせずに、ベタで$_POST["name"]を表示して、inputを影で作るのが多いようで、
以下のようにしました。

すでに料理したものがこちら(お名前欄)
お名前:<?php echo $_POST["name"]; ?>
<input name="name" value="<?php echo $_POST["name"]; ?>" style="display:none;">

Special Thanks

今回マサカリ投げてもらった → @shoutaWATANABE

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?