send post request using form code example

Example 1: javascript send post request

let data = {element: "barium"};

fetch("/post/data/here", {
  method: "POST", 
  body: JSON.stringify(data)
}).then(res => {
  console.log("Request complete! response:", res);
});


// If you are as lazy as me (or just prefer a shortcut/helper):

window.post = function(url, data) {
  return fetch(url, {method: "POST", body: JSON.stringify(data)});
}

// ...

post("post/data/here", {element: "osmium"});

Example 2: post form data

@if($errors->any())                           /*  This 
@foreach($errors->all() as $error)                area is 
  {{ $error }}<br>                                to print
@endforeach                                       message in
@endif                                            the form     */
<form method="post" action="submitmyform">	
       {{ csrf_field()}}               // csrf token
	<p>
		<label>Name</label>
		<input type="text" name="name" value="{{ old("name")}}"/>
	</p>
     <p>
     <label>Email</label>
		<input type="text" name="email" value="{{ old("email")}}"/>	
     </p>
	<p>
     <label>Age</label>
		<input type="text" name="age" value="{{ old("age")}}"/>	
     </p>
      <p>
      	<input type="submit" name="Submit">
      </p>
</form>

Tags:

Php Example