Gform get input value

(Examples)
(Examples)
 
Line 38: Line 38:
</pre>
</pre>
-
This is another example which where you may select a specific form and specific fields to decode. It is also assumed that the values were base 64 encoded.
+
This is another example where you may select a specific form and specific fields to decode. It is also assumed that the values were base 64 encoded.
<pre class="brush:php">
<pre class="brush:php">

Latest revision as of 15:27, 23 July 2012

Description

Use this filter to change the field's value after being retrieved from the database. Use in conjunction with gform_save_field_value to perform low level transformations, such as encrypting/decrypting a field.

Usage

<?php
add_filter("gform_get_input_value", "decrypt_field", 10, 4);
?>


Parameters

$value

(string) Field value to be filtered.

$lead

(Entry Object) Current entry object.

$field

(Field Object) Current Field object.

$input_id

(float) For multi-input fields (i.e. name, address, checkboxes), this parameter will hold the input ID. For single input fields, this parameter will be blank.

Examples

This example assumes the field values were base 64 encoded, and decodes them so that they can be properly displayed. View gform_save_field_value for an example on how to encode the fields.


<?php
add_filter("gform_get_input_value", "decode_field", 10, 4);
function decrypt_field($value, $lead, $field, $input_id){
	return base64_decode($value);
}
?>

This is another example where you may select a specific form and specific fields to decode. It is also assumed that the values were base 64 encoded.


<?php
add_filter("gform_get_input_value", "decode_field", 10, 4);
function decode_field($value, $lead, $field, $input_id){
        //if not the form with fields to decode, just return the unaltered value without checking the fields
        if(absint($lead["form_id"]) <> 94)
                return $value;
       
        //array of field ids to decode
        $decode_fields = array(1,2,3);
 
        //see if the current field id is in the array of fields to decode; decode if so, otherwise return unaltered value
    if(in_array($field["id"],$decode_fields))
        {
                return base64_decode($value);
        }
        else
        {
                return $value;
        }
}
?>

Source Code

This filter is located in forms_model.php

Search the Documentation