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.

Make a form embed conditional

  1. rs468
    Member

    I've embedded a gravity form in one of my WP pages. What I'd like to do is create a condition where I only embed/display the form Monday - Friday...

    Any thoughts?

    Thanks

    Posted 12 years ago on Saturday February 25, 2012 | Permalink
  2. You could create a new page template to use for displaying your form that has this bit of php in it, then assign that to the Page in your admin:

    <?php
    //Give what day of the week it is. Returns Sunday through Saturday.
    	$day = date("l");
    
    	switch ($day) {
    	case Monday: case Tuesday: case Wednesday: case Thursday: case Friday:
    		echo do_shortcode("[gravityform id=1 title=false description=false ajax=false]");
    	break;
    	}
    ?>

    You can set your form ID appropriately here and all of the other parameters as you see fit. You could also include a separate case for Saturday and/or Sunday to display some kind of message like so:

    <?php
    //Give what day of the week it is. Returns Sunday through Saturday.
    	$day = date("l");
    
    	switch ($day) {
    	case Monday: case Tuesday: case Wednesday: case Thursday: case Friday:
    		echo do_shortcode("[gravityform id=1 title=false description=false ajax=false]");
    	break;
    	case Saturday: case Sunday:
    		echo "It's the weekend, no form today!";
    	break;
    	}
    ?>
    Posted 12 years ago on Saturday February 25, 2012 | Permalink
  3. rs468
    Member

    Thanks Rob! I'll one of those solutions...

    Posted 12 years ago on Saturday February 25, 2012 | Permalink
  4. rs468
    Member

    Hi Rob,

    Added a line for EST:
    <?php
    date_default_timezone_set(timezone_name_from_abbr("EST"));
    $today = date("l");
    if ($today == "Tuesday" || $today == "Wednesday"){
    echo $today;
    echo do_shortcode("[gravityform id=6 title=false description=false ajax=false]");

    }
    ?>
    Unfortunately, this won't pull up the id=6 form... I think it may have something to with having conditional logic. This code works for all my other forms that don't contain conditional fields
    here's the page:
    http://50.116.66.243/~ab27853/test-page2/

    Any thoughts?

    Thanks,

    Posted 12 years ago on Wednesday February 29, 2012 | Permalink
  5. You probably need to enqueue the scripts and/or styles, check this out:

    http://www.gravityhelp.com/documentation/page/Gravity_form_enqueue_scripts

    Posted 12 years ago on Wednesday February 29, 2012 | Permalink
  6. rs468
    Member

    Aaah. Nice! worked perfectly. thanks again Rob

    Posted 12 years ago on Thursday March 1, 2012 | Permalink
  7. Right on! Glad to help.

    Posted 12 years ago on Thursday March 1, 2012 | Permalink

This topic has been resolved and has been closed to new replies.