all repos — captcha @ 1f906795e89e40dd5aa06cbe18548c1ad686cc2d

Go package captcha implements generation and verification of image and audio CAPTCHAs.

example: add language dropdown.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 11 May 2011 23:27:57 +0200
commit

1f906795e89e40dd5aa06cbe18548c1ad686cc2d

parent

cb56dd203fae15315b91e7265d5b8c73ca05218a

1 files changed, 24 insertions(+), 9 deletions(-)

jump to
M example/main.goexample/main.go

@@ -49,22 +49,33 @@ }

} const formJavaScript = ` +function setSrcQuery(e, q) { + var src = e.src; + var p = src.indexOf('?'); + if (p >= 0) { + src = src.substr(0, p); + } + e.src = src + "?" + q +} + function playAudio() { + var le = document.getElementById("lang"); + var lang = le.options[le.selectedIndex].value; var e = document.getElementById('audio') + setSrcQuery(e, "lang=" + lang) e.style.display = 'block'; - e.play(); + e.autoplay = 'true'; return false; } -function reload() { - function setSrcQuery(e, q) { - var src = e.src; - var p = src.indexOf('?'); - if (p >= 0) { - src = src.substr(0, p); - } - e.src = src + "?" + q +function changeLang() { + var e = document.getElementById('audio') + if (e.style.display == 'block') { + playAudio(); } +} + +function reload() { setSrcQuery(document.getElementById('image'), "reload=" + (new Date()).getTime()); setSrcQuery(document.getElementById('audio'), (new Date()).getTime()); return false;

@@ -77,6 +88,10 @@ <body>

<script> {JavaScript} </script> +<select id="lang" onchange="changeLang()"> + <option value="en">English</option> + <option value="ru">Russian</option> +</select> <form action="/process" method=post> <p>Type the numbers you see in the picture below:</p> <p><img id=image src="/captcha/{CaptchaId}.png" alt="Captcha image"></p>