Please Note: We are no longer using forums to facilitate standard support. 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.

Form in Modal (Lightbox) Window?

  1. David Peralty
    Administrator

    Hi all, I am trying to have a send to friend feature that uses a modal window to quickly grab the e-mail addresses (from and to) as well as the post URL and title. Is something like this possible/easy or should I push them to another page and use the new query string/populate fields thingy?

    Let me know if it is possible to ajax up Gravity Forms in this way.

    Posted 5 years ago on Sunday October 18, 2009 | Permalink
  2. Dave,
    There are a couple of ways you can do this.
    1- You could load your form in an iframe (most lightbox type scripts support that) and use the query string to pre-populate the fields. That way, you get the ajax feel without having to write any code

    OR

    2- You could embed the form to that post and use a hook to pre-populate the fields. That way you don't have to use an iframe. If you would like to go this way, I can come up with a code snippet for you.

    Posted 5 years ago on Monday October 19, 2009 | Permalink
  3. David Peralty
    Administrator

    I am definitely more interested in doing something like #2. The only field I'd need to pre-populate is a hidden field with the Post URL. Then they put in their e-mail, and the e-mail address they want to send the post to.

    They click submit, and I set the notification settings to use those inputs to shoot off an e-mail to their "friend" with the content of the e-mail being: "Great post for you to look at: URL"

    Posted 5 years ago on Monday October 19, 2009 | Permalink
  4. Sounds good.
    Here is what you need to do:

    1- Add the Post Url hidden field to your form
    a- Allow it to be populated dynamically (advanced tab)
    b- Type "posturl" in the "parameter name" text field

    2- Add the following code snippet to your template's function.php file

    add_filter("gform_field_value_posturl", "populate_post_url");
    function populate_post_url(){
        global $post;
        return get_permalink($post->ID);
    }

    Good Luck.
    Let me know how it goes.

    Posted 5 years ago on Tuesday October 20, 2009 | Permalink
  5. David Peralty
    Administrator

    So far so good, except for JavaScript stuff. I can't get the modal window part to work. I hate JavaScript. Thanks again though.

    Posted 5 years ago on Tuesday October 20, 2009 | Permalink
  6. David Peralty
    Administrator

    It works! :)
    http://hirevine.com/employment/community-management/57/social-media-online-community-manager/

    Thanks!

    Posted 5 years ago on Wednesday October 21, 2009 | Permalink
  7. David Peralty
    Administrator

    I used it for the Send to a Friend function at the bottom of the post. I am using Fancy Box for the JavaScript. :)

    Posted 5 years ago on Wednesday October 21, 2009 | Permalink
  8. Nicely done!! Looks great!

    Posted 5 years ago on Wednesday October 21, 2009 | Permalink
  9. ckovacs
    Member

    I'd love it if somebody could go through this in words of one syllable for me (assume I know my way around WP and PHP to some extent, but not to the extent that I can follow what the advice early). I thought I understood pretty well how all this works, but I'm utterly baffled by the instructions Alex offers above. (I'm working with a lightbox called 'facebox' -- not my choice -- and trying to make posts with title/category/tags/body/image, embedding a shortcode in a page, loading up that page in the lightbox). There's probably a better way to do it.

    Some general guidance would be most welcome...

    Posted 5 years ago on Monday November 30, 2009 | Permalink
  10. I downloaded and installed facebox, and had a modal form working in about 5 minutes... this is how.

    Some of this might not be necessary for you since you're already using the script, but I'm including it for anyone else who might be interested.

    Download facebox, unzip the file and upload the entire folder to your theme directory.

    Open the header.php file and include this inside the < head> section.

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2"></script>
    <script src="<?php bloginfo('template_directory'); ?>/facebox/facebox.js" type="text/javascript"></script>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox()
    });
    </script>

    (you may have to adjust the file paths depending on your setup)

    Open/Create page where you want to include the modal form, go to the content editor and switch to the HTML tab. Then you can add something like this.

    <a href="#info" rel="facebox"><h3>launch form in modal window</h3></a>
    <!-- begin hidden form -->
    <div id="info" style="display:none;">[gravityform id=11 name=1.3Post Form description=false]</div>
    <!-- end hidden form -->

    Basically, You're hiding the form in a div inline in the page. When the facebox script is triggered, it will display the form in a modal window.

    editor screenshot

    Of course, you'll want to actually insert your form id/name in place of the form in the example.

    Save the page and you should see something like this when you click on the link you created.

    modal form screenshot

    There are other options of course, but you can refer back to the facebox script page to read up on those.

    As a note, most of the modal window scripts will allow you to display a hidden inline div or inline content in very similar fashion. The implementation should be pretty much the same for those other scripts. You can refer to the script documentation for details.

    Posted 5 years ago on Monday November 30, 2009 | Permalink
  11. I like the idea here, but I am wondering, if a "contact" form is used, and there is an error when filling out the fields, there is no way to inform the person of any errors. Is this dealt with?

    Posted 5 years ago on Monday December 7, 2009 | Permalink
  12. Instead of using the inline div for the form, you could create a very basic page template to include the form on, then call the page as an iframe to load in the facebox window.

    <a href="http:\\www.yoursite.com\modalformpage\" rel="facebox">launch form in modal window</a>

    When you post the form - since it's an iframe, it should refresh in the modal window and display any errors or the inline confirmation text.

    Posted 5 years ago on Monday December 7, 2009 | Permalink
  13. that is good to hear. Now I will try using facebox, thanks.

    Posted 5 years ago on Monday December 7, 2009 | Permalink
  14. I mentioned facebox because of the earlier example. Most of the modal window scripts I've seen or have used support iframed content so the concept should apply to any of those. Let us know how it goes.

    Posted 5 years ago on Monday December 7, 2009 | Permalink
  15. I know this is all related to "facebox", and the problem is not with gravity forms. I did try the above method, but regardless, whether I call another page or use a hidden div, gravity forms reloads and facebox closes. I use to use cforms (will not go back). Cforms did not reload the page and lightbox windows actually worked. If anyone has a remedy, thanks before hand.

    Posted 5 years ago on Friday December 11, 2009 | Permalink
  16. Facebox was probably a bad example for the second implementation. It uses ajax to call remote content rather than an actual iframe. If you try another script like Fancybox that supports actual iframed content, you should have better luck.

    Posted 5 years ago on Saturday December 12, 2009 | Permalink
  17. thanks, I'll check it out

    Posted 5 years ago on Saturday December 12, 2009 | Permalink
  18. Cristian
    Member

    Hello!

    Could you guys please show me an example of how to create a modal form using FancyBox for Wordpress? (http://blog.moskis.net/downloads/plugins/fancybox-for-wordpress/)

    The FancyBox for WP Plugin is super-great and if I could mange to blend it into a Gravity form, I will be more than super-happy :D

    I've carefully read the above explanations, but I couldn't manage to make it work using the already installed Fancybox for WP Plugin. I wish to have an impressive contact form and I think this is one way to do it.

    Basically I need to insert into the upper right corner of each post (single.php) a text like: "Translate" and when clicked, should link to a modal gravity form.

    Thank you!

    Posted 5 years ago on Monday December 14, 2009 | Permalink
  19. Christian, I'll install the FancyBox plugin on my test site, give it a run and then will post back a quick "how to" showing my results. I'll get to it as soon as I can and post back.

    Posted 5 years ago on Monday December 14, 2009 | Permalink
  20. I am waiting in anticipation for this, myself.

    Posted 5 years ago on Monday December 14, 2009 | Permalink
  21. Cristian
    Member

    Me too :D In the meantime I've tried some experiments using the fancybox tags with gravityform id but nothing good came out :D
    Will persevere!

    Posted 5 years ago on Wednesday December 16, 2009 | Permalink
  22. Hey guys, sorry I haven't got back around to this. I'll try to get to it tonight and post back here. Thanks for your patience.

    Posted 5 years ago on Wednesday December 16, 2009 | Permalink
  23. I've posted a quick example using Gravity Forms with the FancyBox jQuery plugin to create a modal form.

    http://www.gravityhelp.com/creating-a-modal-form-with-gravity-forms-and-fancybox/

    There are several WordPress FancyBox plugins, each with different options, etc. should you choose to use one of those, but the concepts for creating the page template, iframe, etc. would be the same.

    I hope that helps out a bit.

    Posted 5 years ago on Friday December 18, 2009 | Permalink
  24. I appreciate the work done here to help us out with facebox. My goal is that I want to hide the form on the single.php page, but when users inquire, using the form, the information on the single.php is what they are inquiring about. Is there any way to get that data? Seems that creating the form page, and loading into facebox, there is no way to send information related to the actual page they are on. No way to send the "post title" or the url of the page. I understand, this may not be do-able. thanks

    Posted 5 years ago on Sunday December 20, 2009 | Permalink
  25. You can still use the query string parameters to pass information to the form. You just need to configure the fields to be populated dynamically (under advanced tab for each field).

    settings screenshot

    Once you've done that, you simply pass whatever information you want in the link to the iframed form page.. example:

    <a href="http://www.domain.com/modal-popup-iframe/?pagetitle=modal form test&url=http://wp1.domain.com/modaltest" class="iframeFancybox1"><h3>launch iframed form in modal window</h3></a>

    and you end up with something like this.

    pre-populated form screenshot

    Of course, you may want to pass the information to hidden fields instead of what I've done here, but the concept is the same.

    Posted 5 years ago on Sunday December 20, 2009 | Permalink
  26. I will work with this, thanks for the great support. There is so much to learn just with gravityforms, its a powerful tool.

    Posted 5 years ago on Sunday December 20, 2009 | Permalink
  27. This has worked out great. And I'm getting some insight into using hidden fields. Does just what I need, thanks. Ended up using a plugin, fancybox for wordpress. I'm using it for my galleries, and the form here, xhtml strict, no errors. Could not be more pleased.

    Posted 5 years ago on Monday December 21, 2009 | Permalink
  28. Awesome news. I'm glad that helped out. Thanks for the update. Could you post the link to the fancybox plugin you used for other people to use?

    Posted 5 years ago on Monday December 21, 2009 | Permalink
  29. http://blog.moskis.net/downloads/plugins/fancybox-for-wordpress/
    Plugin I used. Below is the code I used in a single template. Used a graphic instead of text as the link to the form
    <a href="http://black/popup//?pagetitle=<?php the_title(); ?>" class="fancybox iframe"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/email.png" alt="inquire about this item"/></a>

    Posted 5 years ago on Monday December 21, 2009 | Permalink
  30. By the way, the URL http://black/ is from my local setup, using Mamp (why you won't find it on the web)

    Posted 5 years ago on Monday December 21, 2009 | Permalink
  31. Wonderful. Thanks again.

    Posted 5 years ago on Monday December 21, 2009 | Permalink
  32. <a href="http://www.domain.com/modal-popup-iframe/?pagetitle=modal form test&url=http://wp1.domain.com/modaltest" class="iframeFancybox1"><h3>launch iframed form in modal window</h3></a>

    I'm back! the code above works, but the & before url= creates errors for xhtml strict. I am using it anyway but is there any way around this?

    Posted 5 years ago on Thursday April 15, 2010 | Permalink
  33. You should be able to validate by replacing the ampersand with the encoded character "& amp;" (no space). You'll also need to move your H3 tag outside of the anchor.

    The code keeps displaying incorrectly here, so you can see the valid markup below.

    markup - http://pastie.org/922082

    validator screenshot

    Posted 5 years ago on Thursday April 15, 2010 | Permalink
  34. thats great, thanks,

    Posted 5 years ago on Friday April 16, 2010 | Permalink

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

Support Tickets

Open A New Support Ticket
 Open A New Priority Support Ticket *

* Developer license holders only