passing data from view to controller not showing data [duplicate]

This is my first post of Laravel 10. I am learning Laravel. I was doing some practice but got stuck in it. My data from view page is not passing to the controller.

//controller code

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class PatientController extends Controller
{
    public function index(){
        return view('reg');
    }
    public function create(Request $request){
        print_r($request->all());
    }
}

// route code web.php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PatientController;

Route::get('/patient', [PatientController::class, 'index']);
Route::post('/patient', [PatientController::class, 'create']);

// view page reg.blade.php

<!doctype html>
<html lang="en">

<head>
  <title>Patient</title>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS v5.2.1 -->
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">

</head>

<body>
  <header>
    <!-- place navbar here -->
  </header>
  <main>
    <form action="{{url("https://stackoverflow.com/")}}/patient" method="post">
        {{ csrf_field() }}
<div class="container">
    <h1 class="text-center">registration</h1>
    <div class="mb-3">
      <label for="" class="form-label">Name</label>
      <input type="text" name="nName" id="iName" class="form-control" placeholder="Name" aria-describedby="helpId">
      <small id="helpId" class="text-muted">please insert name</small>
    </div>

    
      <div class="mb-3">
        <label for="" class="form-label">Email</label>
        <input type="text" name="nEmail" id="iEmail" class="form-control" placeholder="Email" aria-describedby="helpId">
        <small id="helpId" class="text-muted">Help text</small>
      </div>

      <div class="mb-3">
        <label for="" class="form-label">Password</label>
        <input type="password" name="nPassword" id="iPassword" class="form-control" placeholder="Password" aria-describedby="helpId">
        <small id="helpId" class="text-muted">Help text</small>
      </div>

      <input name="nSave" id="" class="btn btn-primary" type="button" value="Save">
</div>
</form>
  </main>
  <footer>
    <!-- place footer here -->
  </footer>
  <!-- Bootstrap JavaScript Libraries -->
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
    integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous">
  </script>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
    integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous">
  </script>
</body>

</html>

I am able to get the form page via http://127.0.0.1:8000/patient but on pressing submit button, it seems nothing is happening.

  • You need only <form action="/patient" .. /> + button <input type="submit" ... />

    – 

  • 3

    “but on pressing submit button, it seems nothing is happening” – that’s because it is not a submit button, since you explicitly set type="button".

    – 

Leave a Comment