I read other answers about my question but they were useless for me.
I can't solve this error.
<form method="post" action="/cards/{{ $cards->id }}/notes">
<div class="form-group">
<textarea name="body" title="body" class="form-control" style="text-align: center"></textarea>
</div>
<div>
<button type="submit" class="btn btn-primary">Add Note</button>
</div>
</form>
and :
Route::get('cards', 'CardsController#index');
Route::get('cards/{cards}', 'CardsController#show');
Route::post('cards/{cards}/notes', 'NotesController#store');
thank for your help
You might need to add a CSRF token to your form. Try this:
<form method="post" action="/cards/{{ $cards->id }}/notes">
{{ csrf_field() }}
<div class="form-group">
<textarea name="body" title="body" class="form-control" style="text-align: center"></textarea>
</div>
<div>
<button type="submit" class="btn btn-primary">Add Note</button>
</div>
</form>
Related
When i submit a post form on my page it doesn't work, it redirects me on the action route with error 419, this is an example of my form:
<form action="{{route('client.login')}}" method="POST">
#csrf
#method('POST')
<h4 class="login-title">Login</h4>
<div class="login-form">
<div class="row">
<div class="col-md-12 col-12 mb--20">
<label>Email*</label>
<input class="mb-0" type="email" name="email" value="{{ old('email') }}">
</div>
<div class="col-12 mb--20">
<label>Password</label>
<input class="mb-0" type="password" autocomplete="current-password" name="password"
value="{{ old('password') }}">
</div>
<div class="col-md-12">
<div class="d-flex align-items-center flex-wrap">
<button type="submit" class="btn btn-black me-3">Login</button>
<div class="d-inline-flex align-items-center">
<input type="checkbox" id="remember" name="remember" class="mb-0 me-1">
<label for="remember" class="mb-0 font-weight-400">Ricordami</label>
</div>
</div>
#if (Route::has('password.request'))
<p>Password dimenticata?</p>
#endif
</div>
</div>
</div>
</form>
I've checked the csrf tokens, and they match.
I've the exact same code on my server-side files and they work perfectly, but doesn't work on my local server.
I can't find anywhere the log of this error.
EDIT:
My issue was in the .env file, I’ve written a ; rather than a :
Remove #method('POST') this line and try because you don't need to mention method="POST", you already mentioned method in form tag.
Welcome you in advance.
Try to add <meta name="csrf-token" content="{{ csrf_token() }}"> in the head of app.blade.php file
This is how I fill my data in a table body:
<tbody>
#foreach($ArrayProducts as $product)
<tr>
<td>{{$product['name']}}</td>
<td>{{$product['description']}}</td>
<td>{{$product['price']}}</td>
<td>{{$product['stock']}}</td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Edit</td>
</tr>
#endforeach
</tbody>
But how I can pass the object that is selected in the button Edit of the product to a form to update the product:
<form method="PUT" action="productos">
#csrf
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" id="nombre" name="name" required>
</div>
<div class="form-group">
<label >Descripcion</label>
<input type="text" class="form-control" id="description" name="description" required>
</div>
<div class="form-group">
<label>price</label>
<input id="price" type="number" class="form-control" name="price" required>
</div>
<div class="form-group">
<label>Stock</label>
<input id="stock" type="number" class="form-control" name="stock" required >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
You will also want to modify this so you know the ID of the product you are editing and do error handling.
<tbody>
#foreach($ArrayProducts as $product)
<tr>
<td>{{$product['name']}}</td>
<td>{{$product['description']}}</td>
<td>{{$product['price']}}</td>
<td>{{$product['stock']}}</td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#product-model-{{ $product['id'] }}">Edit</button></td>
</tr>
#endforeach
</tbody>
#foreach($ArrayProducts as $product)
<div class="model" id="product-model-{{ $product['id'] }}">
<form method="PUT" action="productos">
#csrf
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" id="nombre" name="name" required value="{{ $product['name'] }}">
</div>
<div class="form-group">
<label >Descripcion</label>
<input type="text" class="form-control" id="description" name="description" required value="{{ $product['description'] }}">
</div>
<div class="form-group">
<label>price</label>
<input id="price" type="number" class="form-control" name="price" required value="{{ $product['price'] }}">
</div>
<div class="form-group">
<label>Stock</label>
<input id="stock" type="number" class="form-control" name="stock" required value="{{ $product['stock'] }}">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
#endforeach
I have two almost identical forms. One is meant to edit an item, and the other is meant to create an item. For some reason, the create-form does not react at all to submit button clicks, while the edit/update form works exactly as expected. I can not find any differences between the two that should result in this behavior.
I am as sure as I can be that this has nothing to do with back end. I have monitored network activity, ant the submit button for the create-form does not activate any kind of network activity at all.
Working update form:
#extends ('layout')
#section('middle-content')
<div class="wrapper">
<div id="page" class="container">
<h4>Edit Competition Category</h4>
<form method="POST" action="/competition-categories/{{$competitionCategory->id}}">
#csrf
#method('PUT')
<div class="form-group row">
<label for="competition-category-name-input" class="col-4 col-form-label">Name</label>
<div class="col-8">
<input id="competition-category-name-input" name="name" type="text" class="form-control" required="required" value="{{ $competitionCategory->name }}">
</div>
</div>
<div class="form-group row">
<label for="competition-category-abbreviation-input" class="col-4 col-form-label">Abbreviation</label>
<div class="col-8">
<input id="competition-category-abbreviation-input" name="abbreviation" type="text" class="form-control" required="required" value="{{ $competitionCategory->abbreviation }}">
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="submit" type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
#endsection
Non-responding create-form:
#extends ('layout')
#section('middle-content')
<div class="wrapper">
<div id="page" class="container">
<h4>New Competition Category</h4>
<form method="POST" action="/competition-categories"></form>
#csrf
<div class="form-group row">
<label for="competition-category-name-input" class="col-4 col-form-label">Name</label>
<div class="col-8">
<input id="competition-category-name-input" name="name" type="text" class="form-control" required="required">
</div>
</div>
<div class="form-group row">
<label for="competition-category-abbreviation-input" class="col-4 col-form-label">Abbreviation</label>
<div class="col-8">
<input id="competition-category-abbreviation-input" name="abbreviation" type="text" class="form-control" required="required">
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="submit" type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
#endsection
This line: <form method="POST" action="/competition-categories"></form>
of your non working form, please remove </form> you started and closed it that's why.
I've tried using this link https://www.5balloons.info/example-file-upload-validation-laravel-5-6/
And I manage to get it working by trying to return the FileName but the problem is the file I'm trying to upload is not showing in the folder "storage/app"
Here is my code
Controller
public function letterOfIntent(Request $request)
{
$fileName = "fileName".time().'.'.request()->fileToUpload->getClientOriginalExtension();
$request->fileToUpload->storeAs('logos',$fileName);
return 'success';
}
View
<form method="post" action="/supplier-information/company-officer/letter-of-intent" method="post" enctype="multipart/form-data" data-form-method="create">
{{ csrf_field() }}
<div class="row">
<div class="col-lg-offset-1 col-lg-4">
<label style="color:tomato;">Letter of Intent</label>
<input type="file" class="form-control-file" name="fileToUpload" id="exampleInputFile" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">Please upload a valid image file. Size of image should not be more than 2MB.</small>
</div>
<div class="col-lg-3">
<label>Date of Validity</label>
<input class="form-control" type="date" name="upload_file" id="upload_file" class="form-control">
</div>
<div class="col-lg-3">
<br>
<button type="submit" class="btn btn-primary btn-lg btn-flat text-contrail">Upload</button>
<button type="submit" class="btn btn-success btn-lg btn-flat text-contrail">View</button>
</div>
</div>
</form>
I have a controller ( Laravel ) which will be dynamic create a form as below
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<div class="col-2">
<form class="addform" id="newcheckform" role="form">
'.csrf_field().'
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="'.$row->cust_no.'">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="'.$row->cust.'">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</form>
</div>
</div>
if will be loaded by below script in the blade file
$("#custcheck").load("{{ url('/sales/admin/custcheck') }}");
The form displayed as its should to be.
However I when I submit button. Nothing happened. code as below. Appreciate anyone can help. this script resides in the same blade file.
$(function() {
$(document).on('submit', '#newcheckform', function(e){
alert("Hi");
});
});
You have wrong closing tags for <form> change something like this:
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<form class="addform" id="newcheckform" role="form">
{{csrf_field()}}
<div class="col-2">
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="{{$row->cust_no}}">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="{{$row->cust}}">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</div>
</form>
</div>
This will work.