Oops! Looks like something is missing."; } add_filter( 'gform_submit_button', 'form_submit_button', 10, 5 ); function form_submit_button ( $button, $form ){ $button = str_replace( "input", "button", $button ); $button = str_replace( "/", "", $button ); $button .= "{$form['button']['text']}"; return $button; } /*============================================ GF- Date Assist ==============================================*/ class DW_GF_Date { public function __construct( $args = array() ) { $this->_args = wp_parse_args( $args, array( 'form_id' => false, 'target_field_id' => false, 'source_field_id' => false, 'format' => 'Y-m-d', 'modifier' => false ) ); if( ! $this->_args['form_id'] || ! $this->_args['target_field_id'] ) { return; } add_action( 'init', array( $this, 'init' ) ); } public function init() { if( $this->_args['source_field_id'] ) { add_action( 'gform_pre_submission', array( $this, 'populate_date_on_pre_submission' ) ); } else { add_filter( 'gform_pre_render', array( $this, 'populate_date_on_pre_render' ) ); } } public function populate_date_on_pre_render( $form ) { foreach( $form['fields'] as &$field ) { if( $field['id'] == $this->_args['target_field_id'] ) { $key = sprintf( 'gwpd_%d_%d', $form['id'], $field['id'] ); $value = $this->get_modified_date( $field ); $field['allowsPrepopulate'] = true; $field['inputName'] = $key; add_filter("gform_field_value_{$key}", create_function( '', 'return \'' . $value . '\';' ) ); } } return $form; } public function populate_date_on_pre_submission( $form ) { foreach( $form['fields'] as &$field ) { if( $field['id'] == $this->_args['target_field_id'] ) { $timestamp = strtotime( rgpost( 'input_' . $this->_args['source_field_id'] ) ); $value = $this->get_modified_date( $field, $timestamp ); $_POST[ "input_{$field['id']}" ] = $value; } } } public function get_modified_date( $field, $timestamp = false ) { if( ! $timestamp ) { $timestamp = current_time( 'timestamp' ); } if( GFFormsModel::get_input_type( $field ) == 'date' ) { list( $format, $divider ) = $field['dateFormat'] ? array_pad( explode( '_', $field['dateFormat' ] ), 2, 'slash' ) : array( 'mdy', 'slash' ); $dividers = array( 'slash' => '/', 'dot' => '.', 'dash' => '-' ); $format = str_replace( 'y', 'Y', $format ); $divider = $dividers[$divider]; $format = implode( $divider, str_split( $format ) ); } else { $format = $this->_args['format']; } if( $this->_args['modifier'] ) { $date = date( $format, strtotime( $this->_args['modifier'], $timestamp ) ); } else { $date = date( $format, $timestamp ); } return $date; } } new DW_GF_Date( array( 'form_id' => 1, 'target_field_id' => 17, 'modifier' => '+4 months' ) ); ?>