Two submit buttons in one form
If you give each one a name, the clicked one will be sent through as any other input.
<input type="submit" name="button_1" value="Click me">
One form with two submit buttons and different actions for each button
Refer this :
Multiple submit buttons php different actions
Put this script in your page :
<script>
function submitForm(action)
{
document.getElementById('columnarForm').action = action;
document.getElementById('columnarForm').submit();
}
</script>
Modify your input code :
<input type="image" name="camper" onclick="submitForm('formindb_hoh_1.php')" value="camper" src="../images/apps/camperBtn.png" class="submit_button" />
<input type="image" name="medical" onclick="submitForm('formindb_hoh_2.php')" value="medical" src="../images/apps/medicalBtn.png"class="submit_button" />
Multiple submit buttons in an HTML form
I'm just doing the trick of float
ing the buttons to the right.
This way the Prev
button is left of the Next
button, but the Next
comes first in the HTML structure:
.f {
float: right;
}
.clr {
clear: both;
}
<form action="action" method="get">
<input type="text" name="abc">
<div id="buttons">
<input type="submit" class="f" name="next" value="Next">
<input type="submit" class="f" name="prev" value="Prev">
<div class="clr"></div><!-- This div prevents later elements from floating with the buttons. Keeps them 'inside' div#buttons -->
</div>
</form>
use many submit buttons in the same form
It won't work the way you've written it. Only the submit button you send will be included in request.form
, you'll get an error if you try to use the name of one of the other buttons.
Also, request.form.get
is a function, not a dictionary. You can use request.form.get("Histogram")
-- this will return the value of the Histogram
button if it was used, otherwise it will return None
.
Instead of giving the buttons different names, use the same name but different values.
<form id="package_form" action="" method="post">
<div class="panel-body">
<input type ="submit" name="action" value="Download">
</div>
<div class="panel-body">
<input type ="submit" name="action" value="Histogram">
</div>
<div class="panel-body">
<input type ="submit" name="action" value="Search">
</div>
</form>
Then your Python code can be:
if request.form['action'] == 'Download':
...
elif request.form['action'] == 'Histogram':
...
elif request.form['action'] == 'Search':
...
else:
... // Report bad parameter
HTML form with two submit buttons and two target attributes
It is more appropriate to approach this problem with the mentality that a form will have a default action tied to one submit button, and then an alternative action bound to a plain button. The difference here is that whichever one goes under the submit will be the one used when a user submits the form by pressing enter, while the other one will only be fired when a user explicitly clicks on the button.
Anyhow, with that in mind, this should do it:
<form id='myform' action='jquery.php' method='GET'>
<input type='submit' id='btn1' value='Normal Submit'>
<input type='button' id='btn2' value='New Window'>
</form>
With this javascript:
var form = document.getElementById('myform');
form.onsubmit = function() {
form.target = '_self';
};
document.getElementById('btn2').onclick = function() {
form.target = '_blank';
form.submit();
}
Approaches that bind code to the submit button's click event will not work on IE.
Form with multiple submit buttons or multiple forms
You don't need a separate form for each article, you don't need a hidden input, and you don't need JavaScript. Just use a button instead of an input like the other answer suggested. Any of those buttons will submit the form if they're clicked, and $_POST['id']
will have the value of the button that was clicked.
<button>
is different than <input>
because it's not a self-closing tag. With an <input>
, the value is the button text. But with a <button>
, you can give it a value, and then put the text you want it to have between the tags.
Here's an example based on your code.
<form method="POST" action="{{url('/deleteArticle')}}">
{{ csrf_field() }}
@foreach($articles as $a)
<div class="test">
<div class="name"><?= $a['name_a'] ?></div>
<button type="submit" class="del cross" name="id" value='<?= $a['id_a'] ?>' >X</button>
</div>
@endforeach
</form>
Unrelated to the question, I also fixed the repeated csrf_field and merged the two classes on the button.
Related Topics
Html5 Number Input - Always Show 2 Decimal Places
How to Open a Link in New Tab Using Angular
Make Content Horizontally Scroll Inside a Div
Fixed Position Relative to Parent Container
Select Option Padding Not Working in Chrome
How to Set Filename for Base64 Rendered Pdf Using Object Tag
How to Disable Auto-Play for Local Video in Iframe
Failed to Load Resource: the Server Responded With a Status of 404 (Not Found) CSS
Browsers Try to Download HTML File Instead of Opening
Limit Number of Digits After Decimals in Text Input
Directory Chooser in HTML Page
Angular 6 Component Not Showing Up
How to Force Div Contents to Stay in One Line With HTML and CSS
Fixed Page Header Overlaps In-Page Anchors
How to Make an Image Center (Vertically & Horizontally) Inside a Bigger Div
Does :Before Not Work on Img Elements
Why Doesn't Height: 100% Work to Expand Divs to the Screen Height