post form data code example
Example 1: how to access form data usinf method get
if ( isset( $_POST['submit'] ) ) {
echo '<h2>form data retrieved by using the $_REQUEST variable<h2/>'
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
echo 'Your name is ' . $lastname .' ' . $firstname;
if ( filter_has_var( INPUT_POST, 'submit' ) ) {
echo '<h2>form data retrieved by using $_POST variable<h2/>'
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
echo 'Your name is ' . $lastname .' ' . $firstname;
}
if ( filter_has_var( INPUT_GET, 'submit' ) ) {
echo '<h2>form data retrieved by using $_GET variable<h2/>'
$firstname = $_GET['firstname'];
$lastname = $_GET['lastname'];
}
echo 'Your name is ' . $lastname .' ' . $firstname;
exit;
}
Example 2: post form data
@if($errors->any())
<form method="post" action="submitmyform">
{{ csrf_field()}}
<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>