new Pot(Form)
A Pot - honeypot object - provides security features to forms
Parameters:
Name | Type | Description |
---|---|---|
Form |
HTMLFormElement | form to be secured |
Methods
captcha(keyopt) → {Pot}
Set reCaptcha key or activate reCaptcha to render on this form on Fail
event
NOTE : By default, reCaptcha component is only rendered when form submit failed from validation at the first time
This component requires Google reCaptcha is loaded and a sitekey is provided. If a forceReCaptcha global Options
is already set, the reCaptcha component is forced to be rendered on pot creation.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
string |
<optional> |
if not provided, the pot will use |
Returns:
- Type
- Pot
config(options) → {string}
Set multiple options
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | an object contains custom options |
pot.config({theme : 'dark'});
Returns:
- Type
- string
config(key) → {mixed}
Get an option by key
Parameters:
Name | Type | Description |
---|---|---|
key |
string |
pot.config('key');
Returns:
- Type
- mixed
fail(fn) → {Pot}
By a fail callback to form submission ( form not passing the validation )
Parameters:
Name | Type | Description |
---|---|---|
fn |
function |
pot.fail(function(){ alert('Can not submit!'); });
Returns:
current honeypot
- Type
- Pot
fast(currentopt) → {boolean}
Check if the form submission is too fast
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
current |
Number |
<optional> |
current timestamp |
Returns:
- Type
- boolean
input(name) → {HTMLInputElement}
Get an input by name. Useful inside hooked functions
Parameters:
Name | Type | Description |
---|---|---|
name |
string | input's name |
// for validating
pot.validate(function(){
// pot instance is injected inside hooked function
return this.input('email').value === 'alien.say.hello@earth.to'
});
// or for callback
pot.fail(function(){
this.input('password').value = '';
});
Returns:
- Type
- HTMLInputElement
name(name) → {string}
Change main input's name
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
Returns:
- Type
- string
name() → {string}
Get main input's name
Returns:
- Type
- string
valid() → {boolean}
Check if a honeypot is in valid state
Fires:
Validating
Fail
Returns:
- Type
- boolean
validate(fn) → {Pot}
By a validating function or callback to form submission
Parameters:
Name | Type | Description |
---|---|---|
fn |
function |
pot.validate(function(){ return false; });
Returns:
current honeypot
- Type
- Pot
value(name) → {string}
Providing an input's name, get its value
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
pot.value('register_code').length > 8;
Returns:
- Type
- string
Events
Fail
Callback hook on fail for honeypot
Executed when form is submitted but never passes the validation
Type:
Validating
Validation hook for honeypot - provide validating feature
Executed when form is submitted and validating process takes place first