Contact Form 7 File Download After Submit

So I’m back and decided to post some nifty tips I discover along the way.

I am building a form using Contact Form 7 in my client’s site and after submit a file download should be initiated. So I’m gonna share with you how I was able to resolve this.

First, you have to relate the form with the file download, in my case I only use one form and multiple files. So what I did was to use a dynamic form field using the dynamic text extension – https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/
Added it to my form like this –>

[dynamichidden download_url id:download_url "CF7_DOWNLOADFILE"]

In my functions.php I had to create a shortcode for CF7_DOWNLOADFILE, the function I made determines the file based on the url slug, you can also use a database for this but this switch works for me (for now atleast)

function url2pdf(){
$slug = basename(get_permalink());    
switch($slug){
    case "this url": $filename = "this.pdf"; break;
    default:
    $filename = "pdf-test.pdf";
    break;
}return $filename;
}add_shortcode('CF7_DOWNLOADFILE', 'url2pdf');

Now that I have the file url, I just have to add this to my Additional Settings tab

on_sent_ok: "document.getElementById('formFields').style.display = 'none';
window.open('/folder/'+document.getElementById('download_url').value,'_blank')"

Notice that I also added a .css to hide my form upon submission.

I also wanted my thank you message to have a link to the file, on my Messages tab I added this:

Thank you for your submission. Your download will start shortly, 
if not please <a href="/folder/[download_url]" target="_blank">click here</a>.

And that’s it! I hope someone finds this blog post and find it useful! I also use Contact Form DB to store the form submission and downloads.

Happy coding!

Extra White Space on Widgetkit Accordion

For those like me who are having troubles with YooTheme’s Widgetkit accordion content height matching – here’s the solution:

1.) Make sure that you have set Match Content Height to NO on your accordion setting

2.) Edit your template.js* file and comment out the part where main and sidebar contents are matched – in my template its
//$.matchHeight(‘main’, ‘#maininner, #sidebar-a, #sidebar-b’).match();

Done!

* template.js is found in templates/<template name here>/js

Hide Selected Sub-Menu items from the Menu

Sometimes there are sub-menu items that you want to add to your menu (to get the pretty URL) BUT you don’t want to show it in your navigation. In Joomla 1.5 I would make an alias of the parent item and add the hidden child item/s to that “hidden” parent. Now that I am working on a Joomla 2.5 site I can’t use the same approach I was using before, the more proper way is to add a custom class – say hiddenmenu to your menu item Link Style Class, in the Link Style Options tab AND then add the class in your .css file, like this:

/* HIDE SUB MENU */
li .hiddenmenu {
  display: none;
}

Happy programming!

Corrupted ZIP on Download

I am using Phocadownloads to manage our Joomla 1.5 site .zip downloads, we recently encountered an error where the .zip files are corrupted on download. The files are really not corrupted but something in PD disables the archives from being extracted. You can download the file but you can’t extract it.

Solution: make sure all files in PD has the “Direct Link” box ticked, better yet run this on mysql
UPDATE [tablename] SET `directlink`=’1′ WHERE `directlink`=’0′