The gform_polls_form_pre_results Gravity Forms PHP filter allows you to manipulate the form object before the poll results are calculated for the front-end and entry detail pages.
Usage
To apply this filter to all forms:
add_filter('gform_polls_form_pre_results', 'your_function_name', 10, 1);
To target a specific form, append the form ID to the hook name (format: gform_polls_form_pre_results_FORMID):
add_filter('gform_polls_form_pre_results_2', 'your_function_name', 10, 1);
Parameters
- $form (Form Object): The form to be manipulated.
More information
See Gravity Forms Docs: gform_polls_form_pre_results
Examples
Change form title
This example changes the form title to “Testing”:
add_filter('gform_polls_form_pre_results', 'change_poll_form', 10, 1); function change_poll_form($form){ $form['title'] = 'Testing'; // change the form title return $form; }
Add a CSS class to the form
This example adds a custom CSS class to the form’s CSS class list:
add_filter('gform_polls_form_pre_results', 'add_custom_css_class', 10, 1); function add_custom_css_class($form){ $form['cssClass'] .= ' custom-class'; // add the custom CSS class return $form; }
Remove a specific field from the form
This example removes a field with a specific ID from the form:
add_filter('gform_polls_form_pre_results', 'remove_field_by_id', 10, 1); function remove_field_by_id($form){ $field_id = 5; // specify the field ID to remove foreach ($form['fields'] as $key => $field) { if ($field->id == $field_id) { unset($form['fields'][$key]); } } return $form; }
Modify the field label
This example changes the label of a specific field:
add_filter('gform_polls_form_pre_results', 'modify_field_label', 10, 1); function modify_field_label($form){ $field_id = 3; // specify the field ID to modify $new_label = 'New Label'; // specify the new label foreach ($form['fields'] as &$field) { if ($field->id == $field_id) { $field->label = $new_label; } } return $form; }
Hide the form if user is not logged in
This example hides the form if the user is not logged in:
add_filter('gform_polls_form_pre_results', 'hide_form_if_not_logged_in', 10, 1); function hide_form_if_not_logged_in($form){ if (!is_user_logged_in()) { $form = null; // hide the form if the user is not logged in } return $form; }