ozkan8's avatar

Passing route parameters to form action attribute

Hello,

I'm registering new users from admin panel, then i'm sending mail to new registered user with link to creating password with user id and token.

I have two parameters in url id and token, but in view file i can't pass url parameters to action attribute for post method;

How i can pass route parameters to action attribute in view:

create_password.blade.php

<form class="card" action="{{ route("create-password") }}" method="post">

    @csrf

    <div class="card-body p-6">

        <div class="card-title">Create Password</div>

        @if ($errors->any())
        <div class="alert alert-danger">
            <ul class="m-0 pl-2">
                @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
        @endif

        <div class="form-group">
            <label class="form-label">Password</label>
            <input id="text" type="password" class="form-control" name="password" autocomplete="off" required autofocus>
        </div>

        <div class="form-group">
            <label class="form-label">Confirm Password</label>
            <input id="password" type="password" class="form-control" name="password_confirmation" autocomplete="off" required>
        </div>

        <div class="form-group">
            <label class="form-label">Security Code</label>
            <input type="text" class="form-control" name="security_code" autocomplete="off" required>
        </div>

        <div class="form-footer">
            <input type="submit" value="Create Password" class="btn btn-primary btn-block">
        </div>

    </div>
</form>

routes.php

Route::group(['middleware' => CheckCreatePassword::class], function () {
    Route::get('/create-password/{id}/{token}', "Auth\CreatePasswordController@createPasswordShow");
    Route::post('/create-password/{id}/{token}', "Auth\CreatePasswordController@createPassword")->name("create-password");
});
0 likes
1 reply
ozkan8's avatar
ozkan8
OP
Best Answer
Level 1

Solved.

Problem was that i forgot to add variables from my controller.

public function createPasswordShow($id, $token) {
        return view("auth.create_password")
            ->with("id", $id)
            ->with("token", $token);
    }
<form class="card" action="{{ route("create-password", ["id" => $id, "token" => $token]) }}" method="post">
    .
    .
</form>

Please or to participate in this conversation.