Submit form after second click

I’m trying to get a button to change text on the first click, then on the second click to submit the form.

I found this on the web but how can I get it to submit after changing text on the second click? I’m trying to see if this stops some spam. Thanks

<button id="toggle" onclick="myFunction()">on</button>

        <script>

            function myFunction() {
                var change = document.getElementById("toggle");
                if (change.innerHTML == "on")
                {
                    change.innerHTML = "off";
                }
                else {
                    change.innerHTML = "on";
                }
            }

        </script>

In order to avoid some spam I suggest also trying the honeypot method if you’re not already doing so. It consists in adding an invisible text input to your form. Most bots will fill that in but not a normal user. So based on that you can check if that input has a value and if so invalidate the submission. Another effective method is to generate a unique token each time the form renders and store that both as a value in the session and in a hidden input in the form. Then upon submission you check if both values are the same. These are the best non-intrusive anti-spam methods.

I tried the honeypot but it still gets through. Then it triggers my auto response.

The token idea might work best. Where can I learn how to set that up?

Hi, this article explains it.

My personal approach is combining all that with another check that measures the time since the page is requested until the form is submitted. Bots will fill in a form really really fast :wink:

Thanks I’m going to check it out.

Ok, i didn’t use the token because I found out I’m already using the form key form Magento default.

After looking around a bit I put this together:

[code]
Subscribe

</form>
<script>
//<![CDATA[
    var newsletterSubscriberFormDetail = new VarienForm('newsletter-validate-detail');
        function myFunction() {
            var change = document.getElementById("toggle");
            if (change.innerHTML == "<span><span>Subscribe</span></span>")
            {
                change.innerHTML = "<span><span>Human? Click Again</span></span>";
            }
            else {

if (change.innerHTML == “Human? Click Again”)
{
$(‘#toggle’).submit();
}
}
}
//]]>
[/code]

It seems to work in Chrome but in FireFox it changes the text and goes ahead and submits the form without clicking the second time.

Any ideas?

Thanks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.