PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Hide form if past a certain date

  1. I have 10 registration forms created for 10 events we hold at random times during the month.

    We currently use Event Calendar Pro for our event creation. When I add a new event I just add the shortcode to the event for one of the forms.

    I have created two hidden fields in each of the different forms.
    1. "{embed_post:post_title}" is the merge tag for the post title - Which happens to always be the name of the event
    2. "event_date" and is a dynamically populated field

    The "event_date" is populated with a function that gets the Start Date from ECP:

    /********************************************************************
    Add parameter to Gravity Forms
    ********************************************************************/
    add_filter('gform_field_value_event_date', 'my_custom_population_function');
    function my_custom_population_function($value){
        return tribe_get_start_date(null, false, 'F j, Y - g:i a');
    }

    This all works great and when I form is submitted on an event the title of the email is "Event Title - Event Date" so I do not have to keep creating new forms every time we have a new event.

    I am now being asked if I can disable/hide the forms for past events. Is there a way to use the function above to determine if the value is past the current date and hide the form?

    I was looking at the conditional logic for the form settings maybe I could create a new hidden field to determine if it is in the past and pass a variable of "past-event"? then check the hidden field for that value?

    Posted 11 years ago on Wednesday October 31, 2012 | Permalink
  2. I have gotten pretty close with creating the function that determines if it is in the past.
    http://pastie.org/5145241

    I added the conditional logic to each of the form elements to hide them if true.

    The only remaining issue is that the form title and description are remaining on the page. Is there a way to conditionally hide these as well?

    Posted 11 years ago on Wednesday October 31, 2012 | Permalink
  3. You're using a field in the form to hide the form fields, if the date is passed? Why not embed the form using the function call method and perform your conditional logic there? That way, the whole form will not be displayed if the event has passed. I can't see a way to hide the form title and description when the form is displayed. You're only hiding the inner parts of the form with conditional logic. The form is still there.

    http://www.gravityhelp.com/documentation/page/Embedding_A_Form#Function_Call

    Be sure you include the scripts and styles as documented on that page if you decide to use the function call method of embedding the form.

    Posted 11 years ago on Thursday November 1, 2012 | Permalink
  4. Hey Chris,

    Thanks for that link. I see what you are getting at. The fields I had set are still there just given the "display:none" style so the for is actually still there. This is a much better solution by far.

    My next question would be then how would I dynamically choose which form to use? There is only one template file used for the creation of the events. So placing the function in the template is easy but how would I tell it to use a specific form for the event it is on?

    Posted 11 years ago on Thursday November 1, 2012 | Permalink
  5. It's good that you have just one template for the creation of events; that will make things easier. I posted information on the function call to use. You will need to add some conditions around the function call to change which form is embedded. Your question does not specifically address limiting the display of the form based on the date though. Do you already have that part figured out, but just need to know how to determine what page you're on before deciding which form to display?

    The code might look something like this:

    [php]
    <?php
    if (is_page(100)) {
    	// embed form 17 on page 100
    	gravity_form(17, true, true, false, '', false);
    }
    else if (is_page(733)) {
    	// embed form 5 on page 733
    	gravity_form(5, true, true, false, '', false);
    ]
    // and so on
    ?>

    You can use the WordPress function is_page with page ID, page slug, page title, and multiple of those (so you can pass an array of page IDs if you embed the same form on multiple pages.)

    Somewhere in there you will need to check the value of the custom field from your function tribe_get_start_date and use that in your comparison as well.

    Posted 11 years ago on Friday November 2, 2012 | Permalink