How do I make the form resort to a certain part of the code?

Viewed 48

I am making something for new shadowing students (and I get extra credit) and I have encountered an error. Here is my code.

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Icebreaker</title>
  </head>
  <body>

<form class="#" action="#" method="post">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname"><br><br><br>
  <input type="submit" value="Submit">

</form>


<!--- Insert action code here --->

</body>
</html>

How do I make the action resort to a certain part of the html file?

1 Answers

The action in a form is going to redirect you to another url that is going to process the form submission. So, if the action in the form would be something like:

<form method="post" action="/show_icebreaker">
   @csrf
     .
     .
     .            
     <button type="submit">Submit</button>
</form>

Then, you would have a Route like this: Route::post('/show_icebreaker', '\App\Http\Controllers\HomeController@show_icebreaker');

In the HomeController as in my example, you should have something like:

public function show_add_edit_ps(Request $request){
    $FirstName = $request->fname;
    .
    .

    //You can return a view  
    return view('show_icebreaker_view')->with(['FirstName' => $FirstName]);

}
Related