I'm on Home/Index. I have the following HTML:
<form id="frmCode" style="display: inline-block">
<input type="text" name="ConfirmationCode"/>
<input type="button"/>
<img src="~/Images/loading.gif" id="notificationLoading"/>
</form>
For some reason, if I have the cursor in the ConfirmationCode input and I press the Enter key, the form submits, and redirects to http://localhost:62500/?ConfirmationCode= . The thing is, I've read about this behaviour and I understood it might be somewhat intended behaviour depending on browser and whatnot. But I have this other form,
<form id="frmLogin" class="form-horizontal" role="form">
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="col-sm-8">
<input type="text" name="MailOrUsername" title="Te poți loga introducând mail-ul sau numele de utilizator" data-val="true" data-val-required="De ce apeși aiurea? Bagă ID." class="form-control" placeholder="Mail sau ID" />
</div>
<div class="col-sm-8">
<input type="password" name="Password" title="Introdu parola asociată contului tău" data-val="true" data-val-required="Bagă parola." class="form-control" placeholder="Parola" />
</div>
<input type="checkbox" name="RememberMe" />
<span title="Bifând căsuța asta rămâi autentificat și după ce închizi browserul">Ține-mă minte</span>
<input type="button" onclick="login()" id="btnLogin" style="margin-top: 7px; margin-bottom: -5px" value="Intră" class="btn btn-info" />
<input type="button" onclick="login_hide()" />
<img src="~/Images/loading.gif" id="loginLoading" />
</form>
which doesn't have this behaviour, and nothing happens when I press the Enter key.
The form submits because you hace only 1 input in your form (no additional data needs to be entered).
Change you first form to :
<form id="frmCode" style="display: inline-block">
<input type="text" name="ConfirmationCode"/>
<input type="text" name="ConfirmationCode2"/>
<input type="button"/>
<img src="~/Images/loading.gif" id="notificationLoading"/>
</form>
and the form will not submit when you press Enter
If you want to disable the submition functionality of the form you can add the onsubmit event handler like this:
<form id="frmCode" style="display: inline-block" onsubmit="return false;">
<input type="text" name="ConfirmationCode"/>
<input type="button"/>
<img src="~/Images/loading.gif" id="notificationLoading"/>
</form>
You need to set the type of the button you want to use to submit your form to submit.
<input type="submit" ...>
<form id="frmLogin" class="form-horizontal" role="form">
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="col-sm-8">
<input type="text" name="MailOrUsername" title="Te poți loga introducând mail-ul sau numele de utilizator" data-val="true" data-val-required="De ce apeși aiurea? Bagă ID." class="form-control" placeholder="Mail sau ID" />
</div>
<div class="col-sm-8">
<input type="password" name="Password" title="Introdu parola asociată contului tău" data-val="true" data-val-required="Bagă parola." class="form-control" placeholder="Parola" />
</div>
<input type="checkbox" name="RememberMe" />
<span title="Bifând căsuța asta rămâi autentificat și după ce închizi browserul">Ține-mă minte</span>
<input type="submit" onclick="login()" id="btnLogin" style="margin-top: 7px; margin-bottom: -5px" value="Intră" class="btn btn-info" />
<input type="button" onclick="login_hide()" />
<img src="~/Images/loading.gif" id="loginLoading" />
</form>
More infos on the input element and on control types.
That is the usual browser behaviour, when a user presses enter when using a form.
The form will submit and as there is no action attribute in your form tag, it will go back to the current URL (with any of the form fields/values attached) ?ConfirmationCode=
As mentioned in 'Ubiquitous Developers' comment; your are using html buttons <input type="button"/> and not the html submit button <input type="submit" />. This will not have the default behaviours of the submit button.
Its probable that the writer of the script you had, didn't want to use the default behaviours of html forms. Instead using javascript to decide how the form will behave.
I think that they use some javascript to prevent the submission of the form like this;
How to prevent ENTER keypress to submit a web form?
The first form is a simple form which follows the default browser rules. The rule is pressing enter means clicking the submit button.
<input type="button"/>
above is not a valid submit button, so the browser submits the form.
In the second case the scenario is diffrerent.
<input type="submit" onclick="login()" id="btnLogin" style="margin-top: 7px; margin-bottom: -5px" value="Intră" class="btn btn-info" />
here this is a valid submit button and so in pressing enter key, the browser clicks the button and this button instantly calls the JavaScript function "login()". Now it must be in the code that it does something that prevents the form from submission. may be something like "return false;". So the form doe snot submit.
You can try this. it works
<form method="post" action="yourpage.html">
<input type="text" name="name" class="inputbox" />
<button type="submit" id="btn1">Submit</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
$(".inputbox").on('keyup', function (e) {
if (e.keyCode === 13) {
$("#btn1").click();
}
});
</script>
Related
I'm using FormSubmit to create a contact form in my static website (hosted on a server).
My form looks like this:
<div id="contact-area" class="container">
<h1>~$ contactme</h1>
<br>
<form action="https://formsubmit.co/c379c266434ca1a039bdf03209919395" method="POST">
<div class="form-group">
<div class="form-row">
<div class="col">
<input type="text" name="name" class="form-control" placeholder="Your name..." required>
</div>
<div class="col">
<input type="email" name="email" class="form-control" placeholder="Your e-mail" required>
</div>
</div>
</div>
<div class="form-group">
<textarea maxlength="1000" placeholder="Your message..." class="form-control" name="message" rows="10" required></textarea>
</div>
<input type="hidden" name="_template" value="table">
<input type="text" name="_honey" style="display:none">
<input type="hidden" name="_captcha" value="false">
<input type="hidden" name="_next" value="message_sent.html">
<button type="submit" class="btn btn-lg btn-dark btn-block">Submit</button>
</form>
</div>
My email is verified. When the user clicks on submit button, this message appears in a new page:
" Make sure your form has the method="POST" attribute "
However, I receive the message. That's weird. Anyone know why it says my form should have POST attribute while my form actually has the post attribute.
Your code snippet is all okay. I have tested it, forms are getting submitted, and nothing wrong except the way you implement the "_next" feature. As FormSubmit documentation clearly mentioned you have to provide an alternative URL not just a path or file, it should be a URL.
<input type="hidden" name="_next" value="https://yourdomain.co/thanks.html">
Please change the hidden filed in your form to:
<input type="hidden" name="_next" value="https://yourdomain.co/message_sent.html">
and that should probably work fine.
Additional information:
FormSubmit documentation: https://formsubmit.co/documentation
I guess you have gone wrong in the action of the form.
Try using this:
<form action="https://formsubmit.co/your#email.com" method="POST">
<!-- Your form inputs here -->
</form>
I have a code that submits form by clicking <input type="submit">, and I want to change my form to submit when label, which is outside of the form, is clicked.
What should I do?
Here's my code:
<div class="join">
<p>Join</p>
<span>Join to access all features of the site!</span>
</div>
<form action="join/joinf" method="POST" class="joinform">
<div class="left">
<p>ID<span class="required"> *required</span></p>
<p>PW<span class="required"> *required</span></p>
</div>
<div class="right">
<p><input type="text" name="id" id="id" required>
<p><input type="password" name="pw" required></p>
</div>
<input type="submit" id="formsub" value="join">
</form>
<label for="formsub"><button>join-label</button></label>
Try using Jquery click element, set id for label .
$('#LabelId').click(function(e) {
e.preventDefault();
$("#formsub").submit();
});
I am experiencing a issue detecting if the submit button was clicked. I was give the following form by a CSS designer:
<form action="" method="post">
<div class="form-group">
<label>Username</label>
<input name="username" type="text" class="form-control span12">
</div>
<div class="form-group">
<label>Password</label>
<input name="password" type="password" class="form-controlspan12 form-control">
</div>
Sign In
<div class="clearfix"></div>
</form>
I would like submit the captured information by clicking on the Sign In CSS button. I am used to the usual:
<input type="Submit" value="Sign-In>
button, but not this is different, I am stuck. Any assistance will be appreciated.
try to change
Sign In
with
<button type="submit" class="btn btn-primary pull-right">Sign In</button>
Furthermore you need to set an action attribute on your form element
Give your form and ID = "myform" And try below:
Sign In
My code is
<form method="post">
<input type="text" name="t1" id="t1">
<input type="text" name="t2" id="t2">
<input type="submit" name="s1" id="s1" value="Submit1" onclick='this.form.action="p1.php";'>
<input type="submit" name="s2" id="s2" value="Submit2" onclick='this.form.action="p2.php";'>
</form>
Now I want, if I click on submit1 p1.php should open and I can only access value of text1 and not text2.
Similarly, if I click on submit2 p2.php should open and I can only access value of text2 and not text1.
The pages are openning but I can access both the values ie t1 and t2
I only want to do it with html no js and jquery and I need to make only one form.
NO separate forms allowed.
You can use the attribute formaction on the submit button to change the current action of your form, without using JS. See formaction spec. In case you need to support older browsers like IE9- you can simply use webshim to polyfill it:
<script>
if(!('formAction' in document.createElement('input')){
webshim.polyfill('forms');
}
</script>
<form method="post">
<input type="text" name="t1" id="t1">
<input type="text" name="t2" id="t2">
<input type="submit" name="s1" id="s1" value="Submit1" formaction="p2.php">
<input type="submit" name="s2" id="s2" value="Submit2" formaction="p2.php">
</form>
hy sam,
Your question look like wrong may be you are asking to submit all form values in different action using two submit button in a single form.
may be this code will help you to submit values in different form action
<form method="post">
<input type="text" name="t1" id="t1">
<input type="text" name="t2" id="t2">
<input type="submit" name="s1" id="s1" value="Submit1" formaction="p1.php">
<input type="submit" name="s2" id="s2" value="Submit2" formaction="p2.php">
</form>
If you do not want to use javascript, the only solution that I can think of is to use two HTML forms.
<form method="post">
<input type="text" name="t1" id="t1">
<input type="submit" name="s1" id="s1" value="Submit1" onclick='this.form.action="p1.php";'>
</form>
<form method="post">
<input type="text" name="t2" id="t2">
<input type="submit" name="s2" id="s2" value="Submit2" onclick='this.form.action="p2.php";'>
</form>
So I have a form with two fields, one of these fields needs to have information in to successfully display the next page. How would I disable the submit button until that field has some text in it?
Here's the HTML Code;
<div id="content">
<form action="avatarquery.php" method="POST" id="login-form">
<fieldset>
<p>
<label for="login-username">Server Name:</label>
<input type="text" id="login-username" name="name" class="round full-width-input" autofocus />
</p>
<p>
<label for="login-password">Server IP:</label>
<input type="text" id="login-password" name="ip" class="round full-width-input" />
</p>
<input class="button round blue image-right ic-right-arrow" type="submit" id="register" />
</fieldset>
<br/><div class="information-box round">Please Note: Some servers may not work due to their Configs not having Query Enabled.</div>
</form>
If that has to be done using HTML, then in HTML5, you can use
<input type="text" required />
Otherwise in JavaScript, you can try setting an attribute to the input button.
Until the value is "", you can set the attribute
<input type="submit" disabled />