Laravel form with two submit button and resource controller - laravel

I have 2 submit buttons- 1 for "save", 1 for "show saved list".
I want if "subbutton" is clicked, redirect to resource controller public function store(Request $request), if "list" is clicked- redirect to resource controller public function index().
My functions work well. But I dont know how to link them with different buttons.
create.blade.php
<button type="submit" value="subbutton" name="subbutton" class="btn btn-primary">SAVE</button>
<button type="submit" value="list" name="list" class="btn btn-primary">SHOW</button>

A suggestion would be to transform your listing button to an a tag
SHOW
thereby, the submit button would carry out the form submission and the anchor tag would list the resources.

Related

How to check which button is clicked but from blade template not from controller in laravel 8?

I want to know which button is clicked in the view not in the controller.
I have two buttons like this:
<button value="Show" name="Show">Show</button>
<button value="update" name="update">Update</button>
#if(I click button "show" I want to see the following tags)
<h2>title1</h2>
<label>title 2 </label>
#elseif(I click the second button "update" I want to see the following tag)
<span>title 3 </span><br>
#endif

kendo ui - why do button click refresh the page?

Please find below my code:
Template of customer search form
<script type="text/x-kendoui-template" id="customer-search-view-template">
<div class="searchform" id="searchCustomer">
<form class="frmSearch">
<input name="searchTxt" data-bind="value: customerName" class="k-textbox" />
<button class="k-button" data-bind="click: searchClicked">Search</button>
<button class="k-button" data-bind="click: newClicked">New</button>
</form>
</div>
</script>
customer-search.js where loading above template and creating viewmodel object
$(function(){
var views = {};
templateLoader.loadExtTemplate("customer-search-view-template", "../views/customer-search-template.html");
var layout = new kendo.Layout($('#customer-search-view-template').html());
layout.render($("#main"));
// Create an observable view model object.
var customer = kendo.observable({
customerName: "John",
searchClicked: function() {
this.set("customerName", "Search clicked");
},
newClicked: function() {
this.set("customerName", "New clicked");
}
});
// Bind the view model to the personFields element.
kendo.bind($('#searchCustomer'), customer);
});
When I click the search button, the text is set in the textbox but this also refresh the page with ?searchTxt=Search+clicked in the address bar.
May I know why this button click refresh the page and how do I stop refreshing the page on button click ???
I would try and place the attribute 'type' for each like so:
<button type="button" class="k-button" data-bind="click: searchClicked">Search</button>
<button type="button" class="k-button" data-bind="click: newClicked">New</button>
The page thinks that each are performing a form submit action, but by placing the type attribute, you can access the event you intended for search. You may not need your form tags if you are not going to post any data, but rather just a js event handler. Good luck.
The reason is that you are inside a <form>, which has no settings (URL, method, etc), so the browser's default behavior is probably to perform a GET to the current URL (which is a refresh). You could just use <div> instead of <form> if you just want to execute that method.

<input type="button" /> does not call Spring controller in Internet Explorer 8

I call a spring controller method on a button click in my JSP. It works fine in Firefox. But does not do anything in Internet Explorer 8.
Following is the JSP code
<a href="maintenance.html" >
<input type="button" value="Search" name="action"/>
</a>
Following is the Spring Controller code
#RequestMapping(value={"/","/maintenance"})
public String navigateToMaintenance() {
return "maintenance";
}
There is nothing wrong with your controller. Its a Microsoft Standard that doesn't allow button inside anchor. Remove your a tag and change your code like this
<input type="button" value="Search" name="action" onClick="location.href='maintenance.html'"/>
Or
You can remove button and style your anchor like button

Error on submiting form MVC3 .Net

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" />*#
#* }*#

Closing a dialog mvc3

I have en dialog box where there is an CKEditor inside. But i can't get it to fire the HTTPPost on the partialView.
<form method="post" action="#Url.Action("Description")">
#Html.CKEditor("text", (string)ViewBag.BodyText, "toolbar:'Full'", new { cols = 2000, rows = 5000 })
<p>
<input type="submit" value="#Resources.Resources.ProjectCreateDescriptionSave" onclick="#Html.CKEditorSubmitButtonUpdateFunction();" class="close"/>
</p>
</form>
It requires the class="close" but if it's in the input it closes but dosen't fire the httppost. But if i remove the class="close" it works prefect. IS there an way to combine them?
I think you have a mistake in your click event.
onclick="#Html.CKEditorSubmitButtonUpdateFunction();"
Should read
onclick="CKEditorSubmitButtonUpdateFunction();"
Where CKEditorSubmitButtonUpdateFunction() is the name of your javascript function. There is no need for the appended #Html section.
Edit: and really you shouldnt need an onclick event there? Your form handles the post event action="#Url.Action("Description")"

Resources