前提・実現したいこと
cloud9 Laravel -v5.8.35使用
会員登録画面で確認ボタンを押し、確認画面へ移動する際に以下のエラーメッセージが発生しました。
ご教示よろしくお願い致します。
発生している問題・エラーメッセージ
Undefined index: oldpassword (View: /home/ec2-user/environment/xx/resources/views/auth/register_confirm.blade.php)
該当のソースコード
views\auth\register
@extends('layouts.layout') @section('title', '会員登録入力') @section('content') <form name="form2" method="post" action="{{ route('register_confirm') }}"> @csrf <div id="register" class="wrap2"> <section class="main"> <h1 class="pageTitle">会員情報登録</h1> <p>以下のフォームの項目を入力し、よろしければ「確認画面に進む」ボタンをクリックしてください</p> <table class="formTable"> <tbody> <!-- 省略 --> <tr> <th> パスワード <span class="required">必須</span> <input type="hidden" name="password1"> </th> <td> <p id="password1-error" class="errorMessage"></p> <input type="password" name="password1" size="10" maxlength="16" style="ime-mode:disabled;" value="{{ old('password1') }}"> @if($errors->has('password1')) <p class="text-danger">{{ $errors->first('password1') }}</p> @endif <span class="notes"> ※4~16文字の半角英数字</span> <!--  =ここの空白では改行したくない --> </td> </tr> <tr> <th> パスワード確認 <span class="required">必須</span> </th> <td> <input type="password" name="password2" size="10" maxlength="16" style="ime-mode:disabled;" value="{{ old('password2') }}"> @if($errors->has('password2')) <p class="text-danger">{{ $errors->first('password2') }}</p> @endif </td> </tr> <!-- 省略 --> <button type="submit" name="action" value="back"> 入力内容修正 </button> <button type="submit" name="action" value="submit"> この内容で問い合わせる </button> </form> @endsection
views\auth\register_confirm
@extends('layouts.layout') @section('title', '会員登録確認') @section('content') <form method="post" action="{{ route('register_complete') }}"> @csrf <!-- 省略 --> <label>パスワード</label> {{ $inputs2['oldpassword'] }} <input name="password" type="hidden" value="{{ $inputs2['password']}}"> <!-- 省略 --> <button type="submit" name="action" value="back"> 入力内容修正 </button> <button type="submit" name="action" value="submit"> この内容で問い合わせる </button> </form> @endsection
web.php
Route::post('register/confirm', 'Auth\RegisterController@confirm')->name('register_confirm'); Route::post('register/complete', 'Auth\RegisterController@complete')->name('register_complete');
create_users_table
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->string('kname')->comment('フリガナ'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->string('gender')->length(2); $table->string('birthday'); $table->string('phone_num'); $table->string('postal_code',2)->unique()->comment('郵便番号'); $table->string('prefectures_name')->comment('都道府県名'); $table->string('city')->comment('市区町村'); $table->string('Subsequent_address')->comment('その以降の住所'); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('users'); } }
user.php
<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; protected $fillable = [ 'name', 'kname', 'email', 'email2', 'password1', 'password2', 'gender', 'birthday1', 'birthday2', 'birthday3', 'phone_num1', 'phone_num2', 'phone_num3', 'postal_code1', 'postal_code2', 'area', 'prefectures_name', 'city', 'subsequent_address' ]; protected $hidden = [ 'password', 'remember_token', ]; protected $casts = [ 'email_verified_at' => 'datetime', ]; }
App\Http\controllers\RegisterController
<?php namespace App\Http\Controllers\Auth; use App\User; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Http\Request; class RegisterController extends Controller { use RegistersUsers; protected $redirectTo = '/'; public function __construct() { $this->middleware('guest'); } protected function validator(array $data) { return Validator::make($data, [ 'name' => ['required', 'string', 'max:255'], 'kname' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], 'gender' => 'required', 'birthday' => ['required', 'integer',], 'phone_num' => ['required', 'integer'], 'postal_code' => 'required', 'prefectures_name' => ['required', 'string', 'max:255'], 'city' => ['required', 'string', 'max:255'], 'subsequent_address' => ['required', 'string', 'max:255'] ]); } protected function create(array $data) { return User::create([ 'name' => $data['name'], 'reading' => $data['reading'], 'email' => $data['email'], 'password' => Hash::make($data['password']), 'gender' => $data['gender'], 'birthday' => $data['birthday'], 'phone_num' => $data['phone_num'], 'postal_code' => $data['postal_code'], 'prefectures_name' => $data['prefectures_name'], 'city' => $data['city'], 'subsequent_address' => $data['subsequent_address'] ]); } public function confirm(Request $request) { $inputs2 = $request->all(); return view('auth/register_confirm', ['inputs2' => $inputs2]); } public function complete(Request $request) { \Debugbar::info("test"); $this->validate($request,[ 'name' => 'required', 'kname' => 'required', 'email' => 'required', 'password' => 'required', 'gender' => 'required', 'birthday' => 'required', 'phone_num' => 'required', 'postal_code' => 'required', 'prefectures_name' => 'required', 'city' => 'required', 'subsequent_address' => 'required' ]); $action = $request->get('action', 'back'); $inputs2 = $request->except('action'); \Debugbar::info($inputs2); if($action === 'post') { \Mail::to($inputs2["email"])->send(new RegisterSendmail($inputs2)); $request->session()->regenerateToken(); return view('auth/register_complete'); } else { return redirect() ->route('register') ->withInput($inputs2); } } }
試したこと
下記ページを参考にさせていただき
https://teratail.com/questions/65452
回答に使おうとしている配列の要素、もしくは変数が定義されているかどうかを確認することとありますが、自分のページではどこの事を指しているのかわかりませんでした。
分かった事:postやgetを使う際によく起こるということ。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/17 16:13