I'm currently tutoring myself on Laravel 4 and I encounter a strange problem:
I have a blade form:
<form action="{{url('/')}}" method="POST">
<input type="hidden" name="foo" value="bar"/>
<input type="hidden" name="baz" value="boo"/>
<input type="submit" value="Send"/>
</form>
and a Route:
Route::any('/', function()
{
$data = Input::all();
var_dump($data);
});
Route::get('post-form',function()
{
return View::make('form');
});
If I use Get instead of Post (in the blade form) everything's running perfectly but when I try to use Post the returned array is empty
Any clues ? :)
(forgive my English since i'm french native)
try to use Route::post instead of Route::any and dd instead of var_dump
Route::post('/', function()
{
$data = Input::all();
dd($data);
});
Edit:
you have a little mistake in your html form:
<form action="{{url('/')}}" method="POST">
it should look like this:
<form action="/" method="POST">
I hope it will work this time
I tried your code out and it works perfectly. There is no problem with it.
I suggest you using Route::post when you are sure sending POST data
Related
My problem is that when a form is being submitted just reloads the page without doing anything.
My route looks like this:
Route::post('/subscription/cancel', 'SubscriptionController#cancelSubscription')->name('cancel');
My form:
<form class="subscription-action--forms" action="{{ route('cancel') }}" method="post">
#csrf
<input id="cancel-input" type="submit" value="Cancel Subscription">
</form>
And finally my SubscriptionController cancelSubscription() method, which is not being executed:
public function cancelSubscription() {
if (auth()->user()->isSubscribed()) {
auth()->user()->subscription('Subscription to Ebooks.am')->cancel();
return redirect('/subscription')->with('info', 'Canceled!');
}
return redirect('/subscription');
}
The interesting thing is that this code worked just fine until some point (maybe due to a change in other files, don't know).
Are there other ways to get value of an <input> in laravel besides Input::get('name'); ?
Here is my route that tries and get the value
Route::get('delete_comment_action/{id}', function($id)/
{
$status_Id = Input::get('status_Id');
print_r($status_Id);
exit();
return Redirect::back();
});
here is the form that should have the data in it
<form action="" method="get">
<input type="hidden" name ="status_Id" value="{{$swagger->status_Id}}">
<button type="button" class="btn btn-danger">Delete</button>
</form>
Status_Id should at least equal 1, when i try using, but instead it just displays a blank page.
$variable = Input::get('status_Id');
print_r($variable);
your routes looks okay but change form submit tag instead link
Route::get('delete_comment_action/{id}', function($id){
$status_Id = Input::get('status_Id');
print_r($status_Id);
exit();
return Redirect::back();
});
In Form view change form action and replace anchor tag link with
submit button
<form action="{{{ url("delete_comment_action/$swagger->Id") }}}" method="get">
<input type="hidden" name ="status_Id" value="{{$swagger->status_Id}}">
<input type="submit" value="Delete">
</form>
You are trying to use same route twice. You can't use it. What you have to do is separate routes like the following
This route is to show view
Route::get('test', function() {
return View::make('example');
});
This route will handle when you submit your form
Route::get('newtest', function() {
dd(Input::all());
});
In your example.blade.php
<form action="" method="get">
<input type="text" name="hello">
<input type="submit" value="Submit">
</form>
Imagine I have the following in my routes.php file:
Route::get('/test/{system}/{link}', function($system,$link)
{
return "test ok";
});
Then, I wanna access this route with a form from my view:
<form action="/" method="get">
<input type="text" name="system">
<input type="text" name="link">
<button type="submit">Go!</button>
<form>
What would be the best way to do that? I know I can do something like:
Route::get('/',function(){
$input = Request::only('link','system');
$url = 'test/'.$input['system'].'/'.$input['link'];
return redirect($url);
});
But I'm not sure if it's the correct way to achieve it.
Thanks in advance!
You could have js change the form action and then submit it. Your way is ok, but make sure to put it at the end of the routes file. I would actually have the form submit to some specific route (instead of / maybe /redirect-to or something) and from there redirect.
You can do this. I'm not sure if this is the best process.
In routes.php, do this:
Route::get('/form', function(){
return View::make('formview');
});
Route::get('/formaction', function(){
$link = Request::input('link');
$system = Request::input('system');
return "$link";
});
And in the view, as usual, the following:
<form method="get" action="formaction">
System: <input type="text" name="system" />
Link: <input type="text" name="link" />
<input type="submit" value="ok" />
</form>
The Request of Laravel does not depend on the verb used for the request.
I am having a problem with Kohana 3.3. I cannot get the $_POST values using $this->request->post() on my Controller. I dont know what I did wrong on my code. Hope you can help me out here. BTW, I was able to use Twig on all my templates using Kohana 3.3 but I wasn't able to process the data from my forms. Thank you. :-)
Here is my code:
Controller:
class Controller_Setup extends Controller{
public function action_item_group(){
if (HTTP_Request::POST == $this->request->method()){
// Post has no data
print_r($this->request->post());
}
$this->response->body( Twig::factory('setup/sample_form') );
}
}
View
<form class="form-horizontal" action="item_group" method="post" name="setup_form">
<input type="text" value="">
<button type="submit">Save</button>
</form>
You need to set name or id attributes to your HTML elements. Try this code and see if it's working now:
<form class="form-horizontal" action="item_group" method="post" name="setup_form">
<input name="group_name" type="text" value="">
<button type="submit">Save</button>
</form>
my view:
<form action="<?=base_url()?>index.php/frontend/main_con/temp">
<input type="text" name="temp">
<input type="submit"/>
</form>
Controller:
function temp(){
echo $_GET['temp'];
}
i cant able to reach this function and i got an error
An Error Was Encountered
The URI you submitted has disallowed characters.
So, how to pass form data in controller using GET method?
thanx in advance.
View:
<form action="<?=site_url('controller_name/function_name);?>" method="get">
<input type="text" name="temp">
<input type="submit"/>
</form>
Controller
class controller_name extends CI_Controller{
function function_name(){
echo $this->input->get('temp');
}
}
parse_str($_SERVER['QUERY_STRING'],$_GET);
ONLY worked for me after I added the following line to applications/config/config.php:
$config['uri_protocol'] = "PATH_INFO";
To solve the error go to this line. I personally think, that this is a mistake by design, because black-listing symbols from URI would be much better then white-listing.
As for GET variables .. you would have to use <form method="get" action="/what/ever/">.
Can't you use $this->input->get('temp');