gform_form_tag

gform_form_tag

DescriptionUsageParametersExamplesSubmit Form to Custom HandlerTurn off autocompletionPlacementSource CodeThird-party ResourcesPlugin: Gravity Forms Tag Editor

Description
This filter is executed when the form is displayed and can be used to completely change the form tag (i.e.

).
Usage
1add_filter( 'gform_form_tag', 'form_tag', 10, 2 );
Parameters

$form_tag string
The string containing the

tag

$form Form Object
The current form.

Examples
Submit Form to Custom Handler
This example changes the action of the form tag, submitting the form to a custom form handler.
123456789add_filter( 'gform_form_tag', 'form_tag', 10, 2 );function form_tag( $form_tag, $form ) {    if ( $form['id'] != 3 ) {        //not the form whose tag you want to change, return the unchanged tag        return $form_tag;    }    $form_tag = preg_replace( "|action='(.*?)'|", "action='custom_handler.php'", $form_tag );    return $form_tag;}
Turn off autocompletion
Turn off autocompletion as described in Mozilla developer docs: How to Turn Off Form Autocompletion
The following will be applied only to a form with id 1.
12345678910add_filter( 'gform_form_tag', 'form_tag', 10, 2 );function form_tag( $form_tag, $form ) {if ( $form['id'] != 1 ) { // change 1 to match your form id//not the form whose tag you want to change, return the unchanged tagreturn $form_tag;}// Turn off autocompletion as described here https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion$form_tag = preg_replace( "|action='|", "autocomplete='off' action='", $form_tag );return $form_tag;}
If you want to apply it to all forms simply remove the if statement.
123456add_filter( 'gform_form_tag', 'form_tag', 10, 2 );function form_tag( $form_tag, $form ) {// Turn off autocompletion as described here https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion$form_tag = preg_replace( "|action='|", "autocomplete='off' action='", $form_tag );return $form_tag;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFormDisplay::get_form() in form_display.php
Third-party Resources
Plugin: Gravity Forms Tag Editor
A simple plugin that makes modifying Gravity Forms tags a breeze. Change any attribute of the form tag with just a few lines of code. Visit the plugin page.

發表回覆

您的郵箱地址不會被公開。 必填項已用 * 標註