Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How do I get the contact form in a lightbox similar to how the login form works. Thanks!
Comment | File | Size | Author |
---|---|---|---|
#21 | contactform.JPG | 25.33 KB | spiffyd |
Comments
Comment #1
stella CreditAttribution: stella commentedThis isn't possible at present, not automatically any way.
You could write some javascript to find all "/contact" links and append "/lightbox2" to it so it's "/contact/lightbox2". You would also need to add a
rel="lightframe"
to the anchor link. This would open the contact form in a lightbox when the contact link is clicked, and you could style the form with a page-contact-lightbox2.tpl.php template file in your theme's directory.However, this will open the form in a iframe, rather than treating it like modal content which is what is done to the login form. The disadvantage to using an iframe is that the form isn't closed upon form submission, like with the login form. The advantage is that the iframe will add a scrollbar to accommodate the size of the content. If you want, you can treat it as modal content (just use
rel="lightmodal"
), but you'll need to specify the height and width of the lightbox container (see lightbox2 docs).I'm not adding it to lightbox2 module at this time because there are too many modules that modify the contact form content, e.g. advcontact, contact_forms, content_attach, captcha, mollom, etc. These potentially could modify the size of the content, making it difficult for lightbox2 to estimate the outputted form size.
If enough other people request it, then I'll add the ability for lightbox2 to open the default contact form in a lightbox, but for now, this feature won't be implemented for the reasons outlined above.
Cheers,
Stella
Comment #2
asak CreditAttribution: asak commentedWell... I would very much like to see this happening.
Actually, I would like to see this working with advcontact.module as well.
What i'm trying to work out is how to get a "email the admin about this page" link show an advcontact form in a lightbox.
If anyone could provide the basic code, i will fix it to fit my sizing needs.
Thanks!
Comment #3
stella CreditAttribution: stella commentedIt's now possible to scroll lightmodal boxes (dev version), so I'll take another look at implementing this.
Comment #4
Flying Drupalist CreditAttribution: Flying Drupalist commentedHi, has there been any progress on this?
Thanks for your earlier reply btw stella, I really appreciate all the work you're doing on this.
Comment #5
danielb CreditAttribution: danielb commentedI can easily make a contact link open in a lightbox.
- Create a simpler page template to use for the contact form and other lightframe pages (so you don't get sidebars and menus) (I have used a custom url query string to identify pages that need a simple version of page.tpl.php - and made the switch in template.php)
- Update your menu templates to add the lightframe rel code to the correct link (use the $mid to determine which link is which) and your custom query/args
- Ideally, clicking links from your lightframe simple template pages will also open those pages using the simple template (I have used a regex)
- Ideally submitting a form will take you to a simple template page too, but I haven't figured that out - so my solution is to create a confirmation page in a seperate node, that uses the simple template, which the form redirects to.
- You could be extra tricky and call the javascript Lightbox.end('forceClose'); from your confirmation page ?? I dunno I didn't feel like doing this.
That's the workflow, and theres a heap of different ways to do that.
Oh I should have mentioned that my contact form is made with the webform module because the contact module is too difficult for my clients to administer (change the content at the top of the form).
Comment #6
Wolfflow CreditAttribution: Wolfflow commentedsubscribe. It would be very much appreciate if the comment#5 could be more clear for newbies (i.e. some code example) about the building of template etc.
Thanks
Comment #7
Flying Drupalist CreditAttribution: Flying Drupalist commentedHi danielb, I'm very interested in your solution, I think:
- Update your menu templates to add the lightframe rel code to the correct link (use the $mid to determine which link is which) and your custom query/args
might be the hardest part. I would love to be able to do various things to my menus, I'm just not sure how. Can you please paste some code examples? Thanks!
Comment #8
danielb CreditAttribution: danielb commentedOK I will tell you how I did it. Some of this stuff was already done in my base install (configured by another developer) but I will explain it anyway in case your setup is different.
In my template.php there is this function:
I believe this causes my menu items to be themes using a template file menu-item.tpl.php
Here is my content of menu-item.tpl.php. This includes my modifications too (namely the rel tag - where you can see the properties I put in, and also my 'lightframes' array is a list of $mid (menu ids) which the lightframe should be applied to)
Another important thing is in the function _phptemplate_variables in template.php I have added the following right before the 'return $vars;' bit at the end:
and also added this function in :
These last two bits of code are cut down versions of something I used on another site - you can see the unneeded $hook var being passed through, and the overly complicated way of choosing the function name - you can simplify all of this.
What this last bit of code does is for any url with a query string variable called 'lightframe' will be processed via page-body.tpl.php not page.tpl.php
So a path like ' about-our-company?lightframe ' will be output using page-body.tpl.php not page.tpl.php
So what you need to do now is create the file page-body.tpl.php. I simply copied page.tpl.php and deleted all the sidebars and footer etc.. and put a new class on the body for easy styling later.
Just for fun here is mine:
You can see the function 'fix_my_links' in there. This is to combat the problem of people clicking from one node to another and then getting the sidebars back (warning this code will not work if you already use query strings for something else :/ because it looks for ?lightframe not ?something=blah&lightframe ).
Unfortunatly there is still a problem that submitting forms brings back the old template. In your contact form you can solve this by setting a redirect URL like internal:thank-you?lightframe where 'thank-you' is the alias to the confirmation page node.
So far I have not solved the problem of submitting other forms - like node edit forms.
I don't know if this stuff will work for you exactly as I have pasted it - but hopefully it will give you a big clue on how you can do something similar.
You can have a peek at my work here http://qldswimwear.dev.aspedia.net/ but I can't guarantee this site will be here long but I'm sure you can guess what to google to find the live site.
Comment #9
danielb CreditAttribution: danielb commentedI have changed my mind about something.
In menu.tpl.php instead of
$link = str_replace('">', '?lightframe" ' . $rel . '>',$link);
make it
$link = str_replace('">', '" ' . $rel . '>',$link);
and use jquery to add the query string
better for SEO (you might need to customise the jquery selector if you're using 'rel' for multiple things).
Comment #10
danielb CreditAttribution: danielb commentedStella, one of the biggest problems I found about your login code is that it did not give itself enough width/height to fit the login form. Probably because my heading font and margins are just slightly larger than normal.
I had to physically change the dimensions in your code - perhaps it should be user selectable or somehow automatic.
Comment #11
Flying Drupalist CreditAttribution: Flying Drupalist commentedThanks a lot! I'll be trying to make your implementation work, I'll post more if I run into problems. :)
Comment #12
stella CreditAttribution: stella commentedI will get to this feature request soon, I promise! Unfortunately, it's just gonna have to wait another couple of weeks, sorry.
Comment #13
stella CreditAttribution: stella commentedI've added this feature to Lightbox2, and it will be included in the latest dev of the lightbox2 module, available later today. Just remember to run update.php after upgrading.
Cheers,
Stella
Comment #14
stella CreditAttribution: stella commentedReleased in Lightbox2 6.x-1.9 and 5.x-2.9.
Cheers,
Stella
Comment #15
tjodolv CreditAttribution: tjodolv commentedA small bug - not critical, but annoying?
When contact form in lightbox is enabled, lightbox2 will also take control of the link to the contact form admin pages at admin/build/contact. Not critical, but annoying all the same ;)
Would it be possible to leave that one out, kind of like disabling lightbox for gallery listings?
Comment #16
stella CreditAttribution: stella commented@tjodolv: Oops, ok will fix that. In the meantime you can just disable the lightbox for
admin
andadmin/build/*
pages on admin/settings/lightbox2.Cheers,
Stella
Comment #17
spiffyd CreditAttribution: spiffyd commentedIs there any info for...
1) How to theme the contact lightbox? (e.g. what are the container classes and ids?)
2) What's new in the latest DEV compared to 1.9?
Comment #18
stella CreditAttribution: stella commented1) you can modify some of the lightbox layout settings under "advanced settings" on admin/settings/lightbox2. Alternatively to see the HTML structure for the lightbox, including ids and classes, then use Firebug or the Firefox Web Developer toolbar to view the DOM / Generated Source for the page.
2) There's only been one change to Lightbox2 since the release on 8th Jan. To see the latest commits / changes go to http://drupal.org/project/cvs/55200
Comment #19
spiffyd CreditAttribution: spiffyd commentedThanks stella! Now one more related question...
How do you remove the title text "contact" at the bottom of the contact modal lightboxes?
Comment #20
stella CreditAttribution: stella commentedI'm not sure what you mean - what text?
Comment #21
spiffyd CreditAttribution: spiffyd commentedSee attachment...
Comment #22
stella CreditAttribution: stella commentedHmm the only way that could happen is if there was a
title
attribute on the link to the contact form, e.g.Lightbox2 changes just the
href
attribute and adds arel
one. It does not add / modify the title one. This doesn't happen with my version of Drupal, so I imagine it's added by another contrib module, maybe some sort of tooltip one?Cheers,
Stella
Comment #23
spiffyd CreditAttribution: spiffyd commentedAha!~
My contact link was a primary link. "contact" was used as the description of the primary link. Removing the description removed this title...
Comment #25
hermes_costell CreditAttribution: hermes_costell commentedI enabled the Lightbox override of the contact form, but I had trouble because one of my nodes had the word "contact" at the beginning (e.g. "contact-info") and Lightbox was changing the link (e.g. "contact-info" => "/contact/lightbox2-info").
I went into the lightbox_modal.js file and changed
function lightbox2_contact() {
$("a[@href*='/contact'], a[@href*='?q=contact']").each(function() {
$(this).attr({
href: this.href.replace(/contact?/,"contact/lightbox2"),
rel: 'lightmodal[|width:450px; height:450px;]'
});
});
}
To:
function lightbox2_contact() {
$("a[@href*='/contact'], a[@href*='?q=contact']").each(function() {
if(this.href.substring(this.href.length-8)=="/contact"){
$(this).attr({
href: this.href.replace(/contact?/,"contact/lightbox2"),
rel: 'lightmodal[|width:450px; height:450px;]'
});
}
});
}
Comment #26
stella CreditAttribution: stella commentedthis has already been fixed in the dev version.
Comment #27
pimsn CreditAttribution: pimsn commentedI just added this functionality using preprocessing and a template file in ZEN. I did this because I need two different contact forms, one for signing up for events, which will appear in the lightbox, the other for contact just in regular use.
For the ones interested, this is what i changed the 'template.php' to:
The template file 'contact-mail-page.tpl.php':
It's working fine and everything, but now I wonder how it'd be possible to pass any arguments to the lightbox... I'd like to pass some through the URL, but as there's no new URL opening, which is the keyfeature of a lightbox, how could I get them available in the lightbox?
Any ideas on this? Thanks in advance..
Comment #28
outcom CreditAttribution: outcom commentedA very simple way is to add a rel link and then use CSS to hide the header and navigation.
Example rel link:
Example CSS:
#lightbox #header, #lightbox #navigation {display:none;}
This method can also be used for other forms, such as node creation forms.
Comment #29
jawwad29180 CreditAttribution: jawwad29180 commentedhi all,
i am trying to show the login form in a lightbox2, it is functioning too. but if an user puts wrong information in or just submit the form without filling it out, it goes to a white page showing login form elements. Could somebody help me please?? Thanks.