I have read laravel throwing MethodNotAllowedHttpException and I know that this error often appears when one is POSTing to a GET route, but I am really sure that I am POSTing to a POST route.
Also this does work on my locale Homestead version but its not working on my apache production server.
There is nothing in the Laravel log file.
This is the error:
If one takes a closer look there is GET and POST, I am not sure if something is wrong with the request:
This is start of the from from the blade file (I am not using JS, its a pure HTML based form):
<form action='/users/update/' method='post' id='contactForm'>
{{ csrf_field() }}
<h2>
#lang('list.memb_4')
<input type="submit" class="savebutton" id='contactButton' value="#lang('list.default_41')"></h2>
Any suggestion what could cause this error?
I had to change
<form action='/users/update/' method='post' id='contactForm'>
to
<form action='/users/update' method='post' id='contactForm'>
In my web.php file I also use
Route::post('/users/update', 'UserController#update');
I don't know why - but on my test server Homestead this was no problem, but on my production server this is a problem.
Related
I have included csrf_field() like below
<form action="/submit" method="post" enctype="multipart/form-data">
{{csrf_field()}}
// input fields
</form>
But i get 419 error for this.
I tried clearing the cache also. But no luck.
Only way i could fix this is to include this path to the app/http/middleware/VerifyCsrfToken.php
I want to know why this happens and how do I fix this without adding path to that file?
Hello: I have done tons of html forms in wordpress and am now trying to do the same in laravel. The problem is with submitting the form; it is not going to my destination or passing the post variables as I would expect. (i am getting errors on the loading of the page).
I know it has something to do with the "routes" and possibly also CSRF? (been reading a lot on this and seeing all kinds of info
I have seen things about using Laravel to build a form "open form/close form" but I am trying to find a way to just use an html form
I have the default laravel installed with nothing extra...
I tried adding a "post" route but that did not help...
here is what i have now:
this is from my routes.php file:
Route::post('gz_form', ['as' => 'gz_form', 'uses' => 'cont15_gzap#gzap_cont_function']);
here is the top of my form:
<form method="post" autocomplete="off" action="{{ route('gz_form') }}" >
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<input type="hidden" name="gc_post" value=2 />
(I threw on that token input as some people suggested that...)
Anyway - I am hoping someone can help me with this...
you have to check your route method .. is it post or get .. and check if your route named already or not ..
Route::post('/gz_form', 'YourController#handler')->name('gz_form');
while you using {{ route('gz_form') }} you need to name it
I was able to get this to work using both of your inputs - but once i had it down to the token mismatch - i finally got it to work by changing the input on my form to:
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
i found that somewhere and by doing that the token mismatch went away...
But thanks for your help guys - getting this to work took more than one step and so your help was needed and helpful...
There is a 2 language version on the site, when you turn on Rus the language is added to the URL "/ru" ie it will be http://site/ru, but at the same time, all attempts to send the form end with an error - "MethodNotAllowedHttpException in RouteCollection.php", in the original languages http://site form Normally Are working
My forms:
<form action="/callback" method="post">
Route::post('/callback', 'ApiController#callback');
By registering that route, you're explicitly asking for a POST request, any other method is not allowed.
If you can't control the incoming request's method, then you should try using
Route::get or Route::any (I wouldn't recommend the last one if you're creating an API).
If you are confused about how routes work, I recommend you to use named routes, so you're always sure you're pointing the form to the right direction:
Route::post('/callback', 'ApiController#callback')->name('api.callback');
And then use it for your form in the view just like
<form method="POST" action="{{ route('api.callback') }}">
Or if you don't want to give it a name, just use the action helper
<form method="POST" action="{{ action('ApiController#callback') }}">
I'm having a bit of an issue when it comes to updating a form and and having an file input. Here is what I am working with.
I have a form in laravel 5.1 which has a post method and a hidden 'Patch' method. This works as is should updating the fields that are in the form. However, when it introduce:
<input type="file" id="profile_picture" name="image_url" />
into the form, i get a:
MethodNotAllowedHttpException in RouteCollection.php line 218:
laravel error. I have tried changing the
<input type='hidden' name='_method' value='PATCH'>
to PUT and it still doesnt like it.
My form looks like this:
<form action='{{url("profiles/$user->id")}}' method="post" class="form-horizontal" enctype="multipart/form-data">
route resource looks like this:
Route::resource('profiles', 'ProfilesController');
I can't figure out what I am missing here...Any help is much appreciated.
I believe it has to do with the exact route you are typing out in the "action" parameter matching up with the profile controller's update method.
Try changing
action'{{url("profiles/$user->id")}}'
to
action='{{ route("profiles.update", $user->id) }}'
Additionally, you could use the Laravel Collective HTML package to simply opening and closing of forms.
Also for POST Request types, you need to send the CSRF token along with your form data. If you are using laravel blade template in your view, you may use
{{ csrf_field() }}
which translates to
<input type="hidden" name="_token" value={{ csrf_token() }}
Please refer the documentation for this.
Working with Polymer 1.0, I try to implement the iron-form element, when I use the method "GET" it's working, but when I try to make a "POST" about the same file on the same path error occurs 404 not found.
My custom element (contact-form):
<dom-module id="contact-form">
<template>
<div class="horizontal center-center layout">
<link rel="import" href="add.php">
<div>
<div class="horizontal-saction>
<form is="iron-form" id="form" method="post" content-type="application/json" action="add.php">
<paper-input name="name" label="Name" requiered></paper-input>
<br><br>
<paper-button raised onclick="sumitForm()">Submit</paper-button>
</form>
</div>
</div>
</div>
</template>
<script>
function submitForm(){
document.getElementById('form').submit();
}
Polymer({
is:'contact-form',
});
My add.php contains:
<?php
var_dump($_POST['name']);
?>
The file path add.php is elements/contact-form/add.php and 404 not found, when I "POST", occurs on the same path http: //localhost:5000/elements/contact-form/add.php. I do not understand because it happens. Sorry for my English.
Seems to me your server configuration must be doing something different with GET and PUT requests. YOu make no mention of what server you have and how its configured, but first check in dev tools if you have a chrome browser and watch the traffic to and from the server.
EDIT - further update on some thought in this
Submitting the form
<paper-button id="submit" >Submit</paper-button>
Then in your Polymer object
listeners: {'submit.tap':'_submitlogon'},
_submitLogon: function() {
this.$.form.submit();
}
SECOND EDIT.
If you are using gulp serve, then it is using its own web server. This has no ability to run any php code. So probably what is coming back is the raw text of php source code. If its stored in a place where the server can find it. I am wondering how the ajax request is being handled - since it is expecting (specifically in POST mode, so I don't understand how GET worked) a JSON formatted response. Obviously the source of your PHP isn't json, so it won't recognise the format and error out.