LoginSignup
0
0

More than 1 year has passed since last update.

【凡ミス①】Formタグ外に登録ボタンを配置

Last updated at Posted at 2021-10-08

私の凡ミス集その①です。

Formタグ外に登録ボタンを配置した事が原因で、
登録ボタンが反応しなくなる。

環境

  • PHP7
  • Laravel6
  • Docker

背景

  • ユーザー登録画面と処理機能作成時の凡ミス
  • 登録ボタンを押しても反応無し。エラーすら出ない。笑
  • RegisterController.phpを確認しても問題は見当たらない
  • Web.phpの記述は、Auth::routes();で認証系はバッチリ
  • register.blade.phpの記述を見ても、この時点では間違いが見当たらず
  • 諦めて就寝...

解決

翌朝register.blade.phpを再確認したところ、
Formタグ外に登録ボタンを間違って配置していたおかげで、
入力データがPOSTされていない事を確認。

register.blade.php
     </div>
    </form>
    <button class="btn btn-block" title="アカウント登録" type="submit">
      はじめる
    </button>
    <div>
        アカウントをお持ちの方は<a href="{{ route('login') }}">こちら</a>から
    </div>
   </div>

以下のように修正したら、上手くいった。

register.blade.php
     </div>
          <button class="btn btn-block" title="アカウント登録" type="submit">
       はじめる
       </button>
    </form>
    <div>
        アカウントをお持ちの方は<a href="{{ route('login') }}">こちら</a>から
    </div>
   </div>

終わりに

Formタグの中でPOSTメソッドを定義して登録処理を実行しているので、
登録ボタンをタグ内に置かないと機能しないのは当たり前。

また、この事象はユーザー登録機能に関わらず、ログイン、パスワードリセット、投稿等、
あらゆるPOSTメソッドを使用する処理で起こりうる凡ミスです。

register.blade.php
<form method="POST" action="{{ route('register') }}" class="p-3">
     @csrf

     ・・・・省略・・・・

   <button class="btn btn-block" title="アカウント登録" type="submit">
        はじめる
   </button>
</form>

以上、凡ミス集①でした

0
0
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
0
0