Actually, I editing the post in my blog but when I tried it cant update instead of it creating a new record. I also tried update() function but it can't work. What's wrong with the code? Anyone, please give me some suggestions to improvise my code. I want to understand what's the problem. So, anybody can explain in detail then I will really appreciate this thing.
My Code:
PostController Code:
public function update(Request $request,Post $post)
{
$post->user_id=$request->user()->id;
$post->title=$request->title;
$post->Description=$request->description;
$post->save();
return redirect('/show');
}
Route file Code:
Route::get('posts/edit/{edit}',[PostController::class,'edit']);
Route::post('/update',[PostController::class,'update']);
View Page Code:
<form method="POST" action='/update'>
#csrf
<table class="table table table-striped table">
<div class="form-group">
<label for="name" class="col-form-label text-md-right">Title</label><br/>
<input placeholder="Enter title here" type="text" name="title" value="{{$data->title}}" required/>
</div>
<div class="form-group">
<label for="name" class="col-form-label text-md-right">Description</label>
</div>
<div>
<textarea name="description" required>{{$data->description}}
</textarea></div>
<div>
<input type="submit" name="update" class="btn btn-success" value="Update" required />
</div>
</table>
</form>
Related
I find myself learning to develop modules in PrestaShop but not capturing data from a form to work on it in the back
<form action="{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}" method="post">
<fieldset class="form-group">
<div class="form-group form-group-lg">
<label class="form-control-label" for="input2">Ingresa tu codigo de seguimiento</label>
<textarea required name="comment" class="form-control" id="comment"></textarea>
</fieldset>
<br>
<input type="submit" class="btn btn-primary" value="Buscar">
</div>
This is the function where it should receive the data but I don't know why it doesn't work.
public function getWidgetVariables($hookname, array $configuration){
if(Tools::isSubmit('comment')){
return Tools::getAllValues();
}
}
What am I doing wrong? (im using xampp to run in local)
Currently, I am working on a blog. But when I try to update a post, it's not getting updated and no error is reproduced.
What's wrong with the code? Anyone, please give me some suggestions to improvise my code. I want to understand what's the problem. So, anybody can explain in detail then I will really appreciate this thing.
PostController code:-
public function update(Store $request,Post $post)
{
$data = $request->validated();
$post = $post->update($data);
return redirect('/index')->withMessage('successfully published');
}
View page code:-
<form method="POST" action='/update'>
#csrf
<table class="table table table-striped table">
<div class="form-group">
<label for="name" class="col-form-label text-md-right">Title</label><br>
<input required="required" placeholder="Enter title here" class="" type="text" name="title" class="" value="{{$data->title}}" required/>
</div>
<div class="form-group">
<label for="name" class="col-form-label text-md-right">Description</label>
</div>
<div>
<textarea name="description" class="" required>{{$data->description}}
</textarea></div>
<div>
<input type="submit" name="update" class="btn btn-success" value="Update" required />
</div>
</table>
</form>
Route file code :-
Route::get('posts/edit/{edit}',[PostController::class,'edit']);
Route::post('/update',[PostController::class,'update']);
Change your Route update to this :
Route::post('posts/update',['as'=>'update','uses'=>'PostController#update']);
And in View Page
<form method="POST" action="{{ route('update') }}">
How do I make custom method to get form data? I want this method same with Laravel update method with parameters request and id. I try this but get error.
In controller
public function updatePassword(Request $request, int $id) {
dd($request->all());
}
In route
Route::post('staffs/{id}/upassword', 'Admin\StaffController#updatePassword')->name('admin.staffs.upassword');
In blade file
<form method="post" accept-charset="utf-8" action="{{ action('Admin\StaffController#updatePassword', ['id' => $staff_id]) }}">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label class="control-label" for="password">New Password</label>
<input class="form-control" name="password" type="password">
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label class="control-label" for="password_confirmation">Confirm New Password</label>
<input class="form-control" name="password_confirmation" type="password">
</div>
</div>
</div>
<input class="btn btn-primary" type="submit">
</form>
I am using Laravel 5.4.
here are some stuff to fix:
First in the tag you can set the action to :
action="route('admin.staffs.upassword', $staff_id)" since it's
easier to write and since you already gave the route a name, so why
not using it ;)
Second add {{csrf_field() }} right before your form closing tag
</form>
what error are you getting? the error is probably because you are not using {{csrf_field()}} after the form declaration, it is needed so that laravel can validate the request. if you want to get the data from the form you can use:
$request->get('inputname');
here is my html
<form name="station" method="post" action="/stations/new" role="form">
<div class="form-group">
<label class="control-label required" for="station_name">Name</label>
<input type="text" id="station_name" name="station[name]" required="required" maxlength="255" class="form-control" >
</div>
<div class="form-group">
<div class="checkbox">
<label for="station_active">
<input type="checkbox" id="station_active" name="station[active]" value="1" />Active</label>
</div>
</div>
<div class="form-group">
<button type="submit" id="station_submit" name="station[submit]" class="btn btn-primary">Ajouter</button>
</div>
<input type="hidden" id="station__token" name="station[_token]" class="form-control" value="aze123aze" >
</form>
i want to get my form using the crawler. I tried the selectButton method like this
$form = $crawler->selectButton('station[submit]')->form(array());
but i get the error : InvalidArgumentException: The current node list is empty.
what is the problem ?
Unfortunately I have no enough rating to just write a comment instead of put it in the answer.
So, could you please show how are you getting $crawler? Problem might be:
$crawler not point to DOM which contains this form
this form appears on page after some java script actions(Ajax for example), but not sure that this is your case.
The selectButton method accept the value The button text. So Try with:
$form = $crawler->selectButton('Ajouter')->form(array());
Hope this help
I am newbie in laravel and I try to insert a data form a form having foreign key by using hide such as the code is mention below:-
<form class="form-horizontal" role="form" action="/WhatTodo/store" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="task_id" value=" {{$what->task_id}}">
<input type="hidden" name="work_id" value="{{$what->work_id}}">
<div class="form-group">
<label class="control-label col-sm-2" for="name"> Name</label>
<div class="col-sm-5">
{!!Form::select('name',$name)!!}
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="work">work:</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="work" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-default" value="Submit">
</div>
</div>
</form>
I have the controller with function:-
public function create($id)
{
$what=WhatTodoModel::findorFail($id);
$name=WOrk::lists('name','name');
return view('what/create',compact('what','name'));
}
You haven't really told us what your issue is or what error you're getting, but my guess given the current question is:
Assuming you're trying to implement a resource route and resourceful controller, the create method is used to show a form to create a new object, not edit an existing one. The create method does not take any parameters, therefore $id will be blank and WhatTodoModel::findorFail($id); will throw an exception.
If you want to edit an existing record, you do that using the edit action.
For creating a new record, create shows the form, store saves the record.
For editing an existing record, edit shows the form, update saves the record.