PHP Classes
elePHPant
Icontem

File: lib/template2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Nguyen Duc Thuan  >  Named Buttons Captcha  >  lib/template2.php  >  Download  
File: lib/template2.php
Role: Configuration script
Content type: text/plain
Description: Configuration script
Class: Named Buttons Captcha
Show a CAPTCHA image with validation questions
Author: By
Last change: Can now render as text instead of only image, this helps improve
performance
Date: 3 years ago
Size: 1,898 bytes
 

Contents

Class file image Download
<script type="text/javascript">
var namedButtonCaptcha = {
    onButtonHovered: function(buttonElement) {
        buttonElement.className = 'nbc-button nbc-button-hovered';
    },
    onButtonBlurred: function(buttonElement) {
        if (buttonElement.prevClass) {
            buttonElement.className = buttonElement.prevClass;
        } else {
            buttonElement.className = 'nbc-button';
        }
    },
    onButtonClicked: function(buttonElement) {
        if (this.getElement('ipt-' + buttonElement.id)) {
            this.getElement('nbc-container').removeChild(this.getElement('ipt-' + buttonElement.id));
            buttonElement.className = 'nbc-button';
        } else {
            var el = document.createElement('input');
            el.id = 'ipt-' + buttonElement.id;
            el.name = 'nbc[]';
            el.value = buttonElement.id.substring(3);
            el.type = 'hidden';
            this.getElement('nbc-container').appendChild(el);
            buttonElement.className = 'nbc-button nbc-button-selected';
        }
        buttonElement.prevClass = buttonElement.className;
    },
    getElement: function (id) {
        return document.getElementById(id);
    }
};
</script>
<style type="text/css">
    .nbc-button {cursor:pointer;border:#ccc solid 3px;padding:4px;float:left;width: 40px;margin-left:2px;text-align:center}
    .nbc-button-hovered {border-color: #CE1F21}
    .nbc-button-selected {border-color: #3342E4}
</style>
      
<?php echo $message; ?><br /><br />

<?php foreach ($buttons as $buttonValue => $buttonLabel): ?>
<div id="nbc<?php echo $buttonValue; ?>" onmouseover="namedButtonCaptcha.onButtonHovered(this)"
     onmouseout="namedButtonCaptcha.onButtonBlurred(this)"
     onclick="namedButtonCaptcha.onButtonClicked(this)"
     class="nbc-button"><?php echo $buttonLabel; ?></div>
<?php endforeach; ?>
<div id="nbc-container"></div>