So i have and action button of edit and the fields to be edited on the same page using php. my problem is when i reload the edit button it will come back to the same page and add an additional url data.
function view_branch()
{
$this->load->view('includes/a_header');
$this->profile();
$this->load->view('includes/a_footer');
$this->load->view('admin/content/view_branch');
}
on top is my original method which views my html page view_branch
on the bottom is the button that reloads the page go to controller and finds the edit_branch method
$row[] = '<td class="w3-row" >
<form method="post" class="w3-half"
action="edit_branch/'.$foo->BranchId.'" id="Edit">
<button class="btn btn-default">
<i class="fa fa-edit"></i>
</button>
</form>
</td>';
so this button will go to my controller with the method name edit_branch that holds
public function edit_branch()
{
$this->view_branch();
}
what will happen is that it creates another url that would cause and error
two url edit_branch
http://localhost/GFC/index.php/Admin_Dashboard/edit_branch/edit_branch/CEB1
You could construct the url differently using site_url(). Try this:
$row[] = '<td class="w3-row" >
<form method="post"
class="w3-half"
action="' . site_url('admin_dashboard/edit_branch/'.$foo->BranchId) . '"
id="Edit">
</form>
</td>';
Note: make sure the URL Helper is loaded before using the site_url() function
Related
I am new to laravel. This is my view (bids.new):
<form method="post" action="{{ route('bids.storeBid', $project->id) }}" enctype="multipart/form-data" >
#csrf
*content*
<div class="row pt-4">
<button class="btn btn-primary">Place Bid</button>
</div>
</form>
This is my route:
Route::get('/bids/new/{id}', 'BidController#create')->name('bids.new');
Route::post('/bids/{id}', 'BidController#storeBid')->name('bids.storeBid');
BidController:
public function create($id)
{
$project = Projects::findOrFail($id);
return view('bids.new',compact('project'));
}
public function storeBid(Request $request, $id)
{
*content*
}
When I clicked on Place Bid button in my view, the page is not responding and URL is still showing /bids/new/1 which means the storeBid route was not loaded. I tried using dd($id) at controller but it is not displaying as well so I assumed I have a problem with the route or form in the view.
<div class="row pt-4">
<button type="submit" class="btn btn-primary">Place Bid</button>
</div>
try this one. I hope it will help you. Let me know.
Thank you guys for the comments, I figured out the problem was not because of the form or route but due to some errors on my eloquent in the controllers.
I have some issues with search field in my project. Hopefully someone can help me.
When I type what I want to search and press enter in url i just get
sitelink/?
instead of
sitelink/results?query=someting
Here are parts of code
All search logic is in web.php not in a seperate controller...
web.php
Route::get('/results', function(){
$posts = \App\Post::where('title','like', '%' . request('query') . '%')->get();
return view('results')->with('posts', $posts)
->with('title', 'Search results : ' . request('query'))
->with('settings', \App\Setting::first())
->with('categories', \App\Category::take(6)->get())
->with('query', request('query'));
});
Here is form
<form method="GET" action="/results">
<input class="overlay_search-input" name="query" placeholder="Type and hit Enter..." type="text">
<a href="#" class="overlay_search-close">
<span></span>
<span></span>
</a>
</form>
Also, when I type full url manualy for example
sitelink/results?query=find
It is working just fine but it does not send right url when I press enter on search field
Are you sure you are hitting your route ???
Try to get the query param in your function
Route::get('/results', function(){
$query = Input::get('query');
print_r($query);
$posts = \App\Post::where('title','like', '%' . $query . '%')->get();
});
The issue was in mistype in blade.php
I hope this will help someone.
Essentially, I had a form I header for search but I also had form in frontIndex.blade.php in one was edited form how it should be and in one it was not. So I created includes folder cutter form there and then included where I needed it. Now it is working just fine :)
Replace this one:
<form method="GET" action="action="{{ route('result') }}"">
<input class="overlay_search-input" type="search" value="{{ isset($query) ? $query : '' }}"
name="query" placeholder="Type and hit Enter..." type="text">
<a href="#" class="overlay_search-close">
<span></span>
<span></span>
</a>
</form>
web.php:
Route::get('/result','SearchController#search')->name('result');
Your controller should get the query input:
$query = $request->input('query');
I'm learning laravel 5.4 and i'm doing a sample project. In that I need to do a search from my DB. Below i have attached a screenshot of my interface.
As you can see in the searchbox i have given i need to search "malabe". And i need to get results for that. i have implemented Controller and needed views too. below i have attached my controller
class SearchController extends Controller
{
//search controller
public function search($keydown){
$searchDetails = DB::table('van_Services')
->where('vs_RouteTo','like','%'.$keydown.'%')
->orwhere('vs_RouteFrom','like','%'.$keydown.'%')
->orwhere('vs_Description','like','%'.$keydown.'%')
->orderBy('created_at', 'DESC')
->paginate(12);
return view('search.search', compact('searchDetails'));
}
}
route code
Route::get('/search/{key}','SearchController#search');
here is the div of my search box code,
<div class="col-xs-6 col-sm-2 col-md-2">
<div class="search_box pull-right">
{{--Search Button--}}
<input type="text" name="search" id="search" laceholder="Search"/>
</div>
</div>
My route and code works if i do the url manual,
my problem is how can i make my search box work? any tutorials or tips?
1. If you really need to use URL link.
JS solution is:
// q => Your search word
function redirectSearch(q) {
location.href = '/search/'+q;
}
pass search field value to this function and page redirect automatically.
.
2. You can send GET params to controller.
Front code:
<div class="col-xs-6 col-sm-2 col-md-2">
<div class="search_box pull-right">
<form action="/search" method="GET">
{{--Search Button--}}
<input type="text" name="search" id="search" placeholder="Search"/>
</form>
</div>
Controller code:
public function search(Request $request){
$search = $request->search;
... Your code ...
}
If you use method with request don`t forget about
use Illuminate\Http\Request;
Route:
Route::get('/search','SearchController#search');
My route and code works if i do the url manual,
I assume it's already working and redirection is just your problem.
Just simply use JS/jQuery.
// when ENTER is pressed
$(document).keypress(function (e) {
if (e.which == 13) {
e.preventDefault();
window.location = APP_URL + "/search/" + $('#search').val();
}
});
Goodluck.
When I press remove, it removes the last charity in the database that belongs to the current user.
View (Button that deletes):
<a href="#"> <button class="btn btn-danger pull-right btnPopover" data-
toggle="popover" data-placement="top"> Remove </button> </a>
View (JS that is called):
function ConfirmDelete()
{
true;
}
$(document).ready(function()
{
$('.btnPopover').popover(
{
html: 'true',
title: '<strong> Are you sure you want to Remove? </strong>',
content: '<form style="display: inline;" action="{{
URL::to('remove', array($favourite->id)) }} "> <button class = "btn
btn-success glyphicon glyphicon-ok" onclick="return
ConfirmDelete()"> Yes </button> </form> <button class = "btn btn-
danger glyphicon glyphicon-remove"> No </button> '
});
$('.btnPopover').on('click', function (e)
{
$('.btnPopover').not(this).popover('hide');
});
Route:
Route::get('remove/{id}', 'HomeController#removeFavourite');
Controller (removeFavourite function):
public function removeFavourite($id)
{
Favourites::where('id', $id)->delete();
Session::flash('flash_message', 'Removed successfully!');
return back();
}
The strange thing is, is that I am using the exact same function and JS call in another part of the application and it is working fine!
The problem is, that it deletes the last record belonging to that user in the database.
Thanks
I don't know exactly what your code looks like, but the problem is that your JS is only valid for the last iteration of the loop, which sounds like what you're experiencing.
To fix it, you can move the form inside the popover button so that you can get the correct form link:
Example (moving the form):
<button class="btn btn-danger pull-right btnPopover" data-toggle="popover" data-placement="top" data-content='<form style="display: inline;" action="{{ URL::to('remove', array($favourite->id)) }} "> <button class = "btn btn-success glyphicon glyphicon-ok" onclick="return ConfirmDelete()"> Yes </button> </form> <button class = "btn btn-danger glyphicon glyphicon-remove"> No </button> '> Remove </button>
JS:
$(document).ready(function()
{
$('.btnPopover').popover(
{
html: 'true',
title: '<strong> Are you sure you want to Remove? </strong>',
});
$('.btnPopover').on('click', function (e)
{
$('.btnPopover').not(this).popover('hide');
});
....
This could be a little cleaner if you could access the parent button from the popover, but I couldn't find a way to do that in the API.
Check whether the $id you retrieve in your program(I assume there is some code missing in the question which finds the $id) is the one you want to delete.
Level official documentation says to use following code for deleting models:
$flight = App\Flight::find(1);
$flight->delete();
Find retrieves single model, and where returns a collection, so that might be the issue.
Also make sure that you pass the specific $id of the favourite that needs to be deleted, if not you'll always be deleting the last $id in your loop.
Official Docs
Hi there I have an error when I submit the following form:
<div id="tabs">
<ul>
<li>Project Details</li>
<li>Project Attachments</li>
<li><a href="#Url.Action("Members", "ProjectNetwork", new { IsTab = true })">Project
Network</a></li>
<li>Bulleting Board</li>
<li>Bids Received</li>
</ul>
</div>
<div id="LowerButton">
#Html.Hidden("MainStatus", #Model.Status)
#using (#Html.BeginForm("Dashboard", "Dashboard"))
{
<button type="button" id="MakeComment">
Make a Comment
</button>
<input type="submit" id="GoDashBoard" value="Return to Project List" />
}
</div>
When I press the button "GoDashBoard", The method "Dashboard" in the controller "Dashboard" is not reached. Instead the following error appears:
It tells me that a model property is beign sent to the server. However, there are no model properties inside the dashboard form.. unless I'm sending many forms at the same time. But I dont think thats possible right? Do you guys have any idea of why is trying to set a model property when I'm not actually sending any?
Update:
this is the input of the dashboard action:
public ActionResult Dashboard(int page = 1)
{
var user = (User)Session["User"];
if (user != null)
{...
}}
the input is a default integer. However, I saw the trace of the calls and its submiting another form which is not related to the one im using:
That form is inside of one of the ajax tabs. I dont understand how one form submits another form and they are not nested. Anyone knows a good workaround? because im thinking of receiving both forms in both actions and make some validations.
I solved it by removing the form "Dashboard" and instead adding an invisible link. The button would reference the invisible link:
#*#using (#Html.BeginForm("Dashboard", "Dashboard"))
{ *#
<button type="button" id="MakeComment">
Make a Comment
</button>
<button name="button" type="button" onclick="document.location.href=$('#GoDashBoard').attr('href')">Return to Project List</button>
<a id="GoDashBoard" href="#Url.Action("Dashboard", "Dashboard")" style="display:none;"></a>
#*<input type="submit" id="GoDashBoard" value="Return to Project List" />*#
#* }*#