How to prevent form resubmission when page is refreshed (F5 / CTRL+R)

I would also like to point out that you can use a javascript approach, window.history.replaceState to prevent a resubmit on refresh and back button. <script> if ( window.history.replaceState ) { window.history.replaceState( null, null, window.location.href ); } </script> Proof of concept here: https://dtbaker.net/files/prevent-post-resubmit.php (Link no longer works) I would still recommend a Post/Redirect/Get approach, but this … Read more

jQuery – add additional parameters on submit (NOT ajax)

This one did it for me: var input = $(“<input>”) .attr(“type”, “hidden”) .attr(“name”, “mydata”).val(“bla”); $(‘#form1′).append(input); is based on the Daff’s answer, but added the NAME attribute to let it show in the form collection and changed VALUE to VAL Also checked the ID of the FORM (form1 in my case) used the Firefox firebug to … Read more

jquery disable form submit on enter

If keyCode is not caught, catch which: $(‘#formid’).on(‘keyup keypress’, function(e) { var keyCode = e.keyCode || e.which; if (keyCode === 13) { e.preventDefault(); return false; } }); EDIT: missed it, it’s better to use keyup instead of keypress EDIT 2: As in some newer versions of Firefox the form submission is not prevented, it’s safer … Read more

Multiple submit buttons in an HTML form

I’m just doing the trick of floating 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”> … Read more

Submit form on pressing Enter with AngularJS

Angular supports this out of the box. Have you tried ngSubmit on your form element? <form ng-submit=”myFunc()” ng-controller=”mycontroller”> <input type=”text” ng-model=”name” /> <br /> <input type=”text” ng-model=”email” /> </form> EDIT: Per the comment regarding the submit button, see Submitting a form by pressing enter without a submit button which gives the solution of: <input type=”submit” … Read more

How do you handle multiple submit buttons in ASP.NET MVC Framework?

Here is a mostly clean attribute-based solution to the multiple submit button issue based heavily on the post and comments from Maarten Balliauw. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class MultipleButtonAttribute : ActionNameSelectorAttribute { public string Name { get; set; } public string Argument { get; set; } public override bool IsValidName(ControllerContext controllerContext, … Read more

Prevent users from submitting a form by hitting Enter

You can use a method such as $(document).ready(function() { $(window).keydown(function(event){ if(event.keyCode == 13) { event.preventDefault(); return false; } }); }); In reading the comments on the original post, to make it more usable and allow people to press Enter if they have completed all the fields: function validationFunction() { $(‘input’).each(function() { … } if(good) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)