[Gravity Forms Addon ] Filter
-
I am trying to create a profanity filter for gravity forms but the doucmentation about their addon frame work is not clear I downlaoded the sample code for sample addon and adapted it i am using a filter in my function php to keep out profanity and key words from my contact form my question is in gravity forms how do i add the filters code i am using the sample addon code provided by gravity forms
`/*
* Use an array to search a string
* Allows us to pass the stop words list and our post data
*/
function bld_strpos_arr($haystack, $needle) {
if(!is_array($needle))
{
$needle = array($needle);
}
foreach($needle as $what) {
$pos = stripos($haystack, $what);
if( $pos !== false)
{
return true;
}
}
return false;
}/*
* Our bad words validation function
*/
add_filter(‘gform_validation’, ‘bld_custom_validation’);
function bld_custom_validation($validation_result){
$form = $validation_result[“form”];$stop_words = array(
‘outsource’,
‘Sir/Madam’,
‘Sir/ Madam’,
‘Sir / Madam’,
‘Sir /Madam’,
‘long term relationship’,
);$stop_id = array();
foreach($_POST as $id => $post)
{
if(bld_strpos_arr($post, $stop_words))
{
/*
* We have a match so store the post ID and initiate validation error
*/
$stop_id[] = $id;
}
}if(sizeof($stop_id) > 0)
{
$validation_result[‘is_valid’] = false;foreach($form[‘fields’] as &$field)
{
foreach($stop_id as $id)
{
$the_id = (int) str_replace(‘input_’, ”, $id);if($field[‘id’] == $the_id)
{
$field[‘failed_validation’] = true;
$field[‘validation_message’] = ‘Please do not send us unsolicited messages’;
}
}
}
}//Assign modified $form object back to the validation result
$validation_result[“form”] = $form;
return $validation_result;}’
My Quesiton is how do i add this to the plugin code of below
‘<?
/*
Plugin Name: Gravity Forms PayPal Add-On
Plugin URI: http://www.gravityforms.com
Description: Integrates Gravity Forms with PayPal, enabling end users to purchase goods and services through Gravity Forms.
Version: 1.9
Author: rocketgenius
Author URI: http://www.rocketgenius.com*/
if ( class_exists( ‘GFForms’ ) ) {
GFForms::include_addon_framework();class GFSimpleAddOn extends GFAddOn {
protected $_version = ‘1.0’;
protected $_min_gravityforms_version = ‘1.9’;
protected $_slug = ‘profanityfiler’;
protected $_path = ‘profanityfiltergravityforms/profanityfiler.php’;
protected $_full_path = __FILE__;
protected $_url = ‘http://www.gravityforms.com’;
protected $_title = ‘Profanity Filter Gravity Forms’;
protected $_short_title = ‘Porfanity Filter Gravity Forms’;private static $_instance = null;
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new self;
}return self::$_instance;
}public function plugin_page() {
?>
This page appears in the Forms menu
<?php
}public function form_settings_fields() {
return array(
array(
‘title’ => ‘Simple Form Settings’,
‘fields’ => array(
array(
‘label’ => ‘My checkbox’,
‘type’ => ‘checkbox’,
‘name’ => ‘enabled’,
‘tooltip’ => ‘This is the tooltip’,
‘choices’ => array(
array(
‘label’ => ‘Enabled’,
‘name’ => ‘enabled’,
)
)
)
)
)
);
}public function plugin_settings_fields() {
return array(
array(
‘title’ => ‘Simple Add-On Settings’,
‘fields’ => array(
array(
‘name’ => ‘textbox’,
‘tooltip’ => ‘This is the tooltip’,
‘label’ => ‘This is the label’,
‘type’ => ‘text’,
‘class’ => ‘small’,
)
)
)
)};
}
}
new GFSimpleAddOn();}?>’
The topic ‘[Gravity Forms Addon ] Filter’ is closed to new replies.