Skip to content

Instantly share code, notes, and snippets.

@gicolek
Last active November 12, 2021 06:37
Show Gist options
  • Save gicolek/9333533 to your computer and use it in GitHub Desktop.
Save gicolek/9333533 to your computer and use it in GitHub Desktop.
Gravity Forms overwrite the input
<?php
add_filter( 'gform_field_input', 'gf_field_input', 10, 5 );
function gf_field_input($input, $field, $value, $lead_id, $form_id) {
// we don't want to change the admin look behavior of the form field
if ( IS_ADMIN )
return $input;
// lets create custom form html in case it had the css class assigned
if ( $field['cssClass'] === 'gf-date-picker' ) {
// get the global post values for use with the get_field function
global $post;
$id = $post->ID;
// have we set any values for the location and date field
if ( get_field( 'loc_date', $id ) ) {
// lets star the output buffering
ob_start();
gf_generate_datepicker( $id, $value );
// lets get the output
$input = ob_get_clean();
}
}
return $input;
}
function gf_generate_datepicker($id, $value) {
?>
<input type="text" class="datepicker" value="<?php echo $value; ?>" />
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment