(→Examples) |
|||
| (2 intermediate revisions not shown) | |||
| Line 6: | Line 6: | ||
<pre class="brush:php"> | <pre class="brush:php"> | ||
<?php | <?php | ||
| - | add_filter("gform_merge_tag_filter", " | + | add_filter("gform_merge_tag_filter", "filter_merge_tag", 10, 4); |
?> | ?> | ||
</pre> | </pre> | ||
== Parameters == | == Parameters == | ||
| - | $value | + | ;$value |
:(string) The current merge tag value to be filtered. Replace it with any other text to replace the merge tag output, or return "false" to disable this field's merge tag output. | :(string) The current merge tag value to be filtered. Replace it with any other text to replace the merge tag output, or return "false" to disable this field's merge tag output. | ||
| - | + | ;$merge_tag | |
| - | $merge_tag | + | |
:(string/int) If the merge tag being executed is an individual field merge tag (i.e. {Name:3}), this variable will contain the field's ID. If not, this variable will contain the name of the merge tag (i.e. all_fields). | :(string/int) If the merge tag being executed is an individual field merge tag (i.e. {Name:3}), this variable will contain the field's ID. If not, this variable will contain the name of the merge tag (i.e. all_fields). | ||
| - | $options | + | ;$options |
:(string) The string containing any options for this merge tag. For example, "value,nohidden" would be the options for the following merge tag: {all_fields:value,nohidden}. | :(string) The string containing any options for this merge tag. For example, "value,nohidden" would be the options for the following merge tag: {all_fields:value,nohidden}. | ||
| - | $field | + | ;$field |
:([[Field Object]]) The current [[Field Object]] | :([[Field Object]]) The current [[Field Object]] | ||
| Line 36: | Line 35: | ||
if($merge_tag == "all_fields" && $field["type"] == "hidden") | if($merge_tag == "all_fields" && $field["type"] == "hidden") | ||
return false; | return false; | ||
| - | else if($merge_tag == "2") | + | else if($merge_tag == "all_fields" && $field["id"] == "2") |
return "Call us for detail"; | return "Call us for detail"; | ||
| + | else | ||
| + | return $value; | ||
} | } | ||
?> | ?> | ||
Latest revision as of 15:28, 27 March 2012
Description
Use this filter to dynamically change the merge tag output. Useful when filtering field types from being displayed in the {all_fields} merge tag, or implementing custom field types that require the merge tag output to be different from the value stored with the entry.
Usage
<?php
add_filter("gform_merge_tag_filter", "filter_merge_tag", 10, 4);
?>
Parameters
- $value
- (string) The current merge tag value to be filtered. Replace it with any other text to replace the merge tag output, or return "false" to disable this field's merge tag output.
- $merge_tag
- (string/int) If the merge tag being executed is an individual field merge tag (i.e. {Name:3}), this variable will contain the field's ID. If not, this variable will contain the name of the merge tag (i.e. all_fields).
- $options
- (string) The string containing any options for this merge tag. For example, "value,nohidden" would be the options for the following merge tag: {all_fields:value,nohidden}.
- $field
- (Field Object) The current Field Object
Examples
This example excludes any hidden fields from the {all_fields} merge tag as well as adds a placeholder text for the field whose ID is 2.
<?php
add_filter("gform_merge_tag_filter", "filter_all_fields", 10, 4);
function filter_all_fields($value, $merge_tag, $options, $field){
if($merge_tag == "all_fields" && $field["type"] == "hidden")
return false;
else if($merge_tag == "all_fields" && $field["id"] == "2")
return "Call us for detail";
else
return $value;
}
?>
Source Code
This filter is located in common.php