I've got an file-input which is submitted with a submit button. But theres also a delete button in the same form. So my problem is, when i press the delete button it will say "Please select an file" because the "required" attribute is in the file-input. I want that this message only displays when you press the upload button(of course only if the input is empty).
Here's my Code :
<form>
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">
<input type="submit" name="del_image" value="Delete">
</form>
You could use formnovalidate attribute to skip validation on specific submit button:
<form>
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">
<input type="submit" name="del_image" value="Delete" formnovalidate >
</form>
(function ($) {
$('#my-form').validate({
rules: {},
messages: {},
submitHandler: function () {
return false
}
});
$('#del_image').click(function(){
$("#file").val("");
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<form id="my-form">
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">
<button id="del_image">Delete</button>
</form>
Related
Add a submit button, and specify that the form should go to "/action_page.php".
<form ____________="/action_page.php">
Name: <input type="text" name="name">
<_________________________>
Try this:
<form action="/action_page.php">
Name: <input type="text" name="name">
<input type="submit" value="Send Request">
</form>
You must use:
<form method="get" action="/action_page.php">
<input type="submit" value="Submit"/>
</form>
And learn this https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
So I used PayPal's button creator from their site and it gave me this code:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"
target="_top">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="">
<input type="hidden" name="lc" value="CA">
<input type="hidden" name="item_name" value="">
<input type="hidden" name="item_number" value="">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="bn" value="PP-
DonationsBF:btn_donate_LG.gif:NonHostedGuest">
<input type="image"src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit">
<img alt="" border="0"src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
which is fine, and working. But what I want to do is change the button to btn-primary.
So when I edit my input type from image to button, then change the "src" to class and inside my class have "btn btn-primary". The edited line looks like this:
<input type="button" src="btn btn-primary" border="0" name="submit">
I thought the only thing I was changing was the look of the button. Is there a specific way where I can get btn primary to reference PayPal instead of their donate button? Does the btn-primary need an href?
Thank you.
try this:
<input type="submit" class="btn btn-primary" border="0" name="submit">
type submit will submit the form.
Hope this helps.
How do I send the contents of the form with out sending the contents of my other form on the same page? For example
<form class="form" method="get" action="page.php">
<input type="text" value="hi" name="forminput1">
<input type="submit" value="send">
</form>
<form class="form" method="get" action="page.php">
<input type="text" value="byebye" name="forminput2">
<input type="submit" value="send">
</form>
page.php:
if (isset($_GET['forminput1'])) {
//some code
}
if (isset($_GET['forminput2'])) {
//some code
}
Whenever I submit form #2, I end up submitting form #1.
You have not given any of your inputs a name attribute. Without a name="somename" attribute the browser will not pass anything back on the GET or POST.
If you add a name attribute like this
<form class="form" action="page.php">
<input type="text" value="hi" name="data">
<input type="submit" value="send" name="send">
</form>
<form class="form" action="page.php">
<input type="text" value="byebye" name="data">
<input type="submit" value="send" name="send">
</form>
It will suddenly start to work as you expect.
If you want to make both forms unique you can add a different name to the submit buttons.
<form class="form" action="page.php">
<input type="text" value="hi" name="data">
<input type="submit" value="send" name="send_form1">
</form>
<form class="form" action="page.php">
<input type="text" value="byebye" name="data">
<input type="submit" value="send" name="send_form2">
</form>
and then in your PHP, you will be able to differentiate between which form (button) is being submitted like this
<?php
if ( $_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['send_form1'])) {
// User sent form1
}
if ( $_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['send_form2'])) {
// User sent form2
}
I think you are using the same action....Forms are independent
I'm trying to append the form action with what the user puts in the text box and having some problems, could someone help me out of this jam?
<form action="http://wfbscd13.cadence.com/cgi-bin/motd.cgi?msg=1&cmd=replace&text=" method="get">
<label for="mestext1"></label>
<input type="text" size="100" maxlength="80">
<input type="submit" name="button1" id="button1" value="Replace">
</form>
If, for some reason, you need your action to be hardcoded:
<form id="myForm" action="http://wfbscd13.cadence.com/cgi-bin/motd.cgi?msg=1&cmd=replace&text=" method="get">
<label for="mestext1"></label>
<input type="text" id="mestext1" size="100" maxlength="80">
<input type="button" name="button1" id="button1" value="Replace" onclick="submitForm();">
</form>
<script type="text/javascript">
function submitForm()
{
var myForm = document.getElementById("myForm");
myForm.action = myForm.action + document.getElementById("mestext1").value;
myForm.submit();
}
</script>
This is not the right way to do it though. You should be adding inputs named msg and cmd and hide them if needed. Then your code will look like this:
<form id="myForm" action="http://wfbscd13.cadence.com/cgi-bin/motd.cgi" method="get">
<label for="mestext1"></label>
<input type="hidden" name="msg" value="1">
<input type="hidden" name="cmd" value="replace">
<input type="text" name="mestext1" id="mestext1" size="100" maxlength="80">
<input type="submit" name="button1" id="button1" value="Replace">
</form>
I want to update a field in my html form separately from the rest. I know we can't have embedded forms in html so how can I make this work?
<form name="LabelForm" method='POST' action="lab/CA/ALL/createLabel.do">
<input type="hidden" name="lab_no" value="<%=lab_no%>">
<input type="hidden" name="aNum" value="<%=aNum%>">
<input type="hidden" name="label" value="<%=label%>">
<td><input type="submit" value="Create" /></td>
</form>
In the above code, the submit button is outside the main table which is part of another form called ackform. I want to put the submit button in the main table(so everything's neat and orderly) but make it part of LabelForm. The value that is entered by the user is "label" which I want to submit with the LabelForm.
Here's my guess:
<form name="TDISLabelForm" method='POST' action="lab/CA/ALL/createLabelTDIS.do">
<input type="hidden" name="lab_no" value="<%=lab_no%>">
<input type="hidden" name="accessionNum" value="<%=accessionNum%>">
<input type="hidden" id="label" name="label" value="<%=label%>">
<td><input type="submit" value="Create" /> <input type="button" onclick="form2.submit()" value="save in the hidden form">
</td>
</form>
<form name="form2" target="fr1" action="....your post code..." method="post">
<input type="hidden" id="label" name="label" value="<%=label%>">
</form>
<iframe style="height:1px;width:1px;border:none:" id="fr1"></iframe>