gform_signature_init_options

Description

The gform_signature_init_options filter can be used to customize the Signature Pad initialization options.

Usage

The following would apply to all forms.

add_filter( 'gform_signature_init_options', 'your_function_name', 10, 3 );

Parameters

  • $init_options array
    The options to be used when initializing Signature Pad for this field.
    Refer to Signature Pad documentation for more information about the options.
$init_options = array(
    'dotSize'                => 2, // Radius of a single dot
    'minWidth'               => empty( $this->penSize ) ? 0.5 : $this->penSize, // Minimum width of a line
    'maxWidth'               => rgblank( $this->boxWidth ) ? 2.5 : $this->boxWidth, // Maximum width of a line
    'throttle'               => 16, // Max milliseconds between points
    'minDistance'            => 5, // Minimum distance between points
    'backgroundColor'        => empty( $this->backgroundColor ) ? 'rgba(255,255,255,1)' : $this->backgroundColor, // Background color
    'penColor'               => empty( $this->penColor ) ? 'black' : $this->penColor, // Pen color
    'velocityFilterWeight'   => 0.7, // Smoothing for velocity
);

Examples

Set Background and Pen Color

add_filter( 'gform_signature_init_options', 'customize_signature_options', 10, 3 );
function customize_signature_options( $init_options, $field, $form ) {
    // Target specific form and field
    if ( $form['id'] == 5 && $field->id == 3 ) { // Adjust form ID and field ID as needed
        $init_options['backgroundColor'] = 'rgba(255,255,255,1)'; // White background
        $init_options['penColor'] = 'rgb(0,0,0)'; // Black pen color
    }

    return $init_options;
}

Customized Line Width and Colors

add_filter( 'gform_signature_init_options', 'customize_signature_options', 10, 3 );
function customize_signature_options( $init_options, $field, $form ) {
    $init_options['minWidth'] = 1; // Thicker minimum line width
    $init_options['maxWidth'] = 4; // Thicker maximum line width
    $init_options['throttle'] = 10; // Increased responsiveness
    $init_options['velocityFilterWeight'] = 0.9; // Smoother line drawing

    return $init_options;
}

Since

This filter was added in Gravity Forms Signature Add-On 3.0.2.

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GF_Field_Signature::GF_Field_Signature::get_signaturepad_init_options() in class-gf-field-signature.php.

It was previously located in GF_Field_Signature::get_supersignature_init_options().