0

Auto Populate a field in Gravity Form

This filter is executed before displaying each field and can be used to dynamically populate fields with a default value.

This filter can also be used to pre-select or pre-check drop down, radio button and checkbox items.

Note: This filter requires that the “Allow field to be populated dynamically” option is checked in the field editor’s advanced tab.
[code language=”php”]
<?php
add_filter("gform_field_value_email", "populate_email");
?>
[/code]
Parameters

$value

(string) The string containing the current field value to be filtered.

Examples

The following example populates the date field with a hardcoded value. It assumes that the date field is configured to “Allow field to be populated dynamically” and that the parameter name is set to “date”

[code language=”php”]
<?php
add_filter("gform_field_value_date", "populate_date");
function populate_date($value){
return "10/10/2010";
}
?>

[/code]
The following example populates a 3 column list field with some values. It assumes that the list field is configured to “Allow field to be populated dynamically” and that the parameter name is set to “list”
[code language=”php”]
<?php
add_filter("gform_field_value_list", "populate_list");
function populate_list($value){
return array("row 1 – col1","row 1 – col2", "row 1 – col3",
"row 2 – col1", "row 2 – col2", "row 2 – col3",
"row 3 – col1", "row 3 – col2", "row 3 – col3");

}
?>

[/code]

Sandeep Kumar

Sandeep kumar is a web developer and a professinal blogger. He works for latest technologies and write articles what he learn. In ICodeHub he share web languages tutorials and other programming tips and tricks. if you need some help or have some suggestion then mail him at sandeep92pal@gmail.com without any hesitation. He believes in learning and sharing.