Search code examples
formshidegravity

how to show/hide gravity forms at Preset time?


I want to disable or hide gravity forms all-time on my website ...but every day:

show at 10:00 AM and hide 10:15 AM .

Similar to the Gravity Form settings section -Restrictions-Schedule form

thanx


Solution

  • You can use the Gravity Forms "Schedule form" setting to apply a daily schedule by...

    1. Copy this snippet to your theme's functions.php file:
    add_filter( 'gform_pre_render', function( $form ) {
    
        if( rgar( $form, 'scheduleForm' ) ) {
            if( ! $form['scheduleStart'] ) {
                $form['scheduleStart'] = date( 'm/d/Y', current_time( 'timestamp' ) );
            }
            if( ! $form['scheduleEnd'] ) {
                $form['scheduleEnd'] = date( 'm/d/Y', current_time( 'timestamp' ) );
            }
        }
    
        return $form;
    } );
    
    1. Set your form schedule via Form Settings › Restrictions › Schedule form.

      • Specify your desired daily start and end times via the Start and End Time settings.
      • Leave the Start and End Date inputs EMPTY.

    That's it. The snippet will handle converting your empty dates into the current day allowing your times to be applied as daily limits.

    EDIT

    You can download this as a plugin here: https://gravitywiz.com/gravity-forms-daily-form-schedule/