(→Description) |
(→Examples) |
||
| Line 36: | Line 36: | ||
return base64_encode($value); | return base64_encode($value); | ||
| + | } | ||
| + | ?> | ||
| + | </pre> | ||
| + | |||
| + | This is another example where you may select a specific form and specific fields to encode. | ||
| + | |||
| + | <pre class="brush:php"> | ||
| + | <?php | ||
| + | add_filter("gform_save_field_value", "save_field_value", 10, 4); | ||
| + | function save_field_value($value, $lead, $field, $form){ | ||
| + | //if not the form with fields to encode, just return the unaltered value without checking the fields | ||
| + | if(absint($form["id"]) <> 94) | ||
| + | return $value; | ||
| + | |||
| + | //array of field ids to encode | ||
| + | $encode_fields = array(1,2,3); | ||
| + | |||
| + | //see if the current field id is in the array of fields to encode; encode if so, otherwise return unaltered value | ||
| + | if(in_array($field["id"],$encode_fields)) | ||
| + | return base64_encode($value); | ||
| + | else | ||
| + | return $value; | ||
} | } | ||
?> | ?> | ||
Latest revision as of 15:29, 23 July 2012
Description
Use this filter to change the field's value before saving it to the database. Use in conjunction with gform_get_input_value to perform low level transformations, such as encrypting/decrypting a field.
Usage
<?php
add_filter("gform_save_field_value", "save_field_value", 10, 4);
?>
Parameters
- $value
- (string) The current entry value to be filtered.
- $lead
- (Lead Object) The current entry.
- $field
- (Field Object) The field from which the entry value was submitted.
- $form
- (Form Object) The form from which the entry value was submitted.
Examples
This example base 64 encodes the field values. View gform_get_input_value for an example on how to decode the fields.
<?php
add_filter("gform_save_field_value", "save_field_value", 10, 4);
function save_field_value($value, $lead, $field, $form){
return base64_encode($value);
}
?>
This is another example where you may select a specific form and specific fields to encode.
<?php
add_filter("gform_save_field_value", "save_field_value", 10, 4);
function save_field_value($value, $lead, $field, $form){
//if not the form with fields to encode, just return the unaltered value without checking the fields
if(absint($form["id"]) <> 94)
return $value;
//array of field ids to encode
$encode_fields = array(1,2,3);
//see if the current field id is in the array of fields to encode; encode if so, otherwise return unaltered value
if(in_array($field["id"],$encode_fields))
return base64_encode($value);
else
return $value;
}
?>
Source Code
This filter is located in forms_model.php