I'm using Dropzone with Laravel and no other threads about this problem have solved my issue.
Currently I load dropzone.js from a cdn.
And, as told in their doc, I just use these lines where I had to include the token with Laravel:
<form
action="{{ route('store_photo_path',['zip' => $flyer->zip, 'street' => $flyer->street]) }}"
class="dropzone"
>
{{ csrf_field() }}
</form>
On my PhotoController, the token arrives right so data is being recieved, but file is totally empty, so I can't manipulate the images. Here is the AJAX response (Laravel's Request object type):
{"_token":"Ng24JDmKn3ylX6p5sFmFvgDcsLp983BZ8IL7pXIN","file":{}}
I'm not using any kind of jQuery method or extending Dropzone behaviour, just trying to make it work in the most simple way Dropzone says it should work. I've checked including enctype does not work because removes the file object and Dropzone does not include it in their documentation, and you shouldn't include more input fields based on their documentation again.
Also, $_POST var has the same information (just the token and the file object empty).
Thanks.
Try adding the attribute enctype="multipart/form-data" to the form, which allows file uploads.
Related
I have a html form inside one of my views that is supposed to get an image the user uploads and save it, the form is below:
<form class="col-lg-12" action="/banner/store/">
The form itself is quite large, but later on there's a to end it. It was supposed to redirect me to the banner/store where my Banner controller have a dd() function so I can confirm everything is okay. But instead, I get a blank white screen and the url goes banner/store/?.
The routes to the BannerController seems to be correct since banner/create works, the problem is when I go from create to store, but anyways, here's how I set the Routes:
Route::resource('banner', 'BannerController');
Any ideas why my banner/store won't work? And why is there a question mark on the end of the url? Sorry if this may be a dumb error, I'm still learning coding.
Your action is is wrong. When you use the resource static method then the store-url is the same as the GET url.
You can achive your goal with:
<form class="col-lg-12" action="{{ route('banner.store') }}" method="POST">
See more information in documentation.
When you updating your banner, you can't use the browser native form with PUT.
See in this document how laravel will handle that for you.
I working with vue.js inside laravel blade ,
I want to parse my product id (vue.js variable) to laravel routing function parameter I tried more than solutions but it doesn't work like:
<form action="{{ route('cart.add', #{{this.productID}}) }}" method="POST">
please, help me
thanks
This won't work, as PHP is Pre-processor, it will render first, JS doesn't execute before that.
Instead of that you can replace your value with pattern, and replace that pattern using JS.
<form action="{{ route('cart.add', ['__ID__']) }}" method="POST">
Now before submitting, you can read URL of action using JS and replace it with the value of your VueJS variable.
You cannot access your vue variables in your blade file. What you should do is move your <form> inside a Vue component and use the variable there. And to be able to use your laravel named routes in .vue files you can use this package.
I have required in my input element and I want to set custom error message there.
this works:
oninvalid="this.setCustomValidity('custom error')"
But I want to read that error message from resources which is in json file. I'm using i18n and ng2-translate which works fine if I'll do:
<span>{{'General.EmptySearch' | translate }}</span> it displays my error message.
so If I'll do that:
oninvalid="this.setCustomValidity('{{'General.EmptySearch' | translate }}')"
it says
Binding to event property 'oninvalid' is disallowed for security reasons, please use (invalid)=...
If 'oninvalid' is a directive input, make sure the directive is imported by the current module.
ok I'll change it. I'm doing that:
(invalid)="this.setCustomValidity('{{'General.EmptySearch' | translate }}')"
error is:
Got interpolation ({{}}) where expression was expected at column 24 in [this.setCustomValidity('{{'General.EmptySearch' | translate }}')]
What's wrong?
Here is my form:
int .ts file
searchval: FormGroup;
ngOnInit() {
this.searchval = new FormGroup({
Search: new FormControl('')
});
}
and html
<form (ngSubmit)="onSubmit(searchval)" [formGroup]="searchval">
<input type="text" class="form-control" required formControlName="Search" placeholder="{{ 'General.Search' | translate }}">
<button type="submit"></button>
</form>
OK, so you are using the model-driven form syntax.
Check out the official doc on form validation. It shows how to do form validation the proper way. It ALSO shows how to have validation messages in your code (vs in your template), which is what your question was about. Once your validation messages are in your code, you'll have no problem translating them.
Side note: I'm really curious why you wanted to validate your fields watching the (invalid) DOM event. I've never seen it done that way.
To pull partial views dynamically in laravel, you would use ajax. From a security standpoint, you would normally use a token that laravel provides to avoid csrf attacks.
Many times, you don't need an entire HTML form, you just use jquery to post data, so you can retrieve a partial view as a response, and inject it into your HTML.
I understand that in an HTML form, you can include a token for laravel to avoid csrf, but if it's an ajax request via jquery without a form, and you have many elements on the same page doing different things via ajax on their individual click events for example, do you need multiple different tokens for each when you do the post to protect yourself from csrf attacks, or can you create a single global line in HTML like:
<div style="display: none;" data-token="{{ csrf_token() }}">
In a certian area on the page, that you can use for all your non-form ajax requests when you write jquery post request for. What I am asking is, for non form element jquery post requests, can you use a single data-token attribute, or should each non form jquery element have its own csrf_token data attribute sent to the route to prevent a csrf attack?
Try to create a global variable in javascript that will hold the current value of _token, you can add this code to your html header
<script> var _token = '<?php echo csrf_token(); ?>'; </script>
then put that _token to each ajax request
(assuming that you filtered the route with csrf checking)
I've just created a form with blade and for some reason its posting with GET even though the HTML says POST and to a different URL (see gif http://cl.ly/image/381k1j0t3x3c )
Routes:
http://cl.ly/image/101V1g2l2X1K
Controler:
http://cl.ly/image/1P2b0O0u3U0q
Blade File:
http://cl.ly/image/2m3B0g3g1T1S
Has anyone had this issue before, anyone see something dumb I've missed?
In your view, remove <form role='form'> tag. Don't wrap form with another form
{{ Form::open(['action'=>'CategoryController#adminStoreCategory']) }}
....
{{ Form::close() }}