{"id":5500,"date":"2018-01-19T19:31:22","date_gmt":"2018-01-19T19:31:22","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/avoid-multiple-form-submissions\/"},"modified":"2018-01-19T19:31:28","modified_gmt":"2018-01-19T19:31:28","slug":"avoid-multiple-form-submissions","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/avoid-multiple-form-submissions\/","title":{"rendered":"Avoid multiple form submissions"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By PHP Builder Staff<\/div>\n<div class=\"\">on April 17, 2012<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<p>Does your database suffer from &#8220;duplicate post&#8221; syndrome? The cure isn&#8217;t too difficult. Here is a simple way to prevent users from submitting the same form multiple times.<\/p>\n<p>First, declare a session variable to store a serial number for each form. I call mine &#8220;$userLastAction.&#8221; Then, in every form where duplicate submission is a problem, include a hidden field, and set the value to $userLastAction+1:<\/p>\n<p>&lt;INPUT TYPE=HIDDEN NAME=lastAction VALUE=&lt;?= $userLastAction+1 ?&gt;&gt;<\/p>\n<p>Finally, verify that the form has not been previously submitted before acting on the submission:<\/p>\n<p>if($lastAction&gt;$userLastAction and inputIsValid(&#8230;)){<br \/>\u00a0 $userLastAction++; \/\/ Increment serial number<br \/>\u00a0 \/\/ Act on form here<br \/>}<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>multiple form submissions<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-5500","post","type-post","status-publish","format-standard","hentry","category-tips"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/5500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=5500"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/5500\/revisions"}],"predecessor-version":[{"id":5638,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/5500\/revisions\/5638"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=5500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=5500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=5500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}