Skip to content

Instantly share code, notes, and snippets.

@adeguntoro
Created November 9, 2019 09:02
Show Gist options
  • Save adeguntoro/f52deab1c0d0de596d46f9ef9958a378 to your computer and use it in GitHub Desktop.
Save adeguntoro/f52deab1c0d0de596d46f9ef9958a378 to your computer and use it in GitHub Desktop.
modal form
<?php
namespace App\Http\Controllers;
use App\Form;
use Illuminate\Http\Request;
class FormController extends Controller
{
public function create()
{
//
return view('form.create');
}
public function store(Request $request)
{
//
$request->validate([
'name' => 'required',
'club' => 'required',
'country' => 'required',
'score' => 'required',
]);
$goalscorer= new Form();
$goalscorer->name=$request->get('name');
$goalscorer->club=$request->get('club');
$goalscorer->country=$request->get('country');
$goalscorer->score=$request->get('score');
$goalscorer->save();
//return response()->json(['success'=>'Data is successfully added']);
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="_token" content="{{csrf_token()}}" />
<title>Champion League Goalscorer</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.3/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="container">
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" id="open">Open Modal</button>
<form method="post" action="{{url('chempionleague')}}" id="form">
@csrf
<!-- Modal -->
<div class="modal" tabindex="-1" role="dialog" id="myModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="alert alert-danger" style="display:none"></div>
<div class="modal-header">
<h5 class="modal-title">Uefa Champion League</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="form-group col-md-4">
<label for="Name">Name:</label>
<input type="text" class="form-control" name="name" id="name" required>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="Club">Club:</label>
<input type="text" class="form-control" name="club" id="club" required>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="Country">Country:</label>
<input type="text" class="form-control" name="country" id="country" required>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label for="Goal Score">Goal Score:</label>
<input type="text" class="form-control" name="score" id="score" required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button class="btn btn-success" id="ajaxSubmit">Save changes</button>
</div>
</div>
</div>
</div>
</form>
</div>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
/*
jQuery(document).ready(function(){
jQuery('#ajaxSubmit').click(function(e){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: "{{ url('/chempionleague') }}",
method: 'post',
data: {
name: jQuery('#name').val(),
club: jQuery('#club').val(),
country: jQuery('#country').val(),
score: jQuery('#score').val(),
},
success: function(result){
if(result.errors)
{
jQuery('.alert-danger').html('');
jQuery.each(result.errors, function(key, value){
jQuery('.alert-danger').show();
jQuery('.alert-danger').append('<li>'+value+'</li>');
});
}
else
{
jQuery('.alert-danger').hide();
$('#open').hide();
$('#myModal').modal('hide');
}
}});
});
});
*/
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment