Textpattern tips, tutorials and code snippets

Collect contact name and email before file download

If you want to ask people to provide their name and email address before permitting them to download a file, here is a simple method that makes use of the plugin com_connect.

  1. Download the most recent release of com_connect.
  2. Install and activate the plugin.

Create a signup form article

In the article that will contain the signup form requesting access to the file download, enter the following:

<txp:com_connect to="your-email@example.com" thanks_form="file_download">
    <txp:com_connect_text label="Name"  />
    <txp:com_connect_text label="Organisation" /> 
    <txp:com_connect_email />
    <txp:com_connect_submit label="Get File" />
</txp:com_connect>

Replace the email address in the above code and save the above code in your article.

Create a file_download form

In the Presentations › Forms pane, create a form of type misc and name it file_download with the following content.

<p>Thank you. Download your file <a href="https://yoursite.com/file_download/6" title="some title">here</a>.</p>

Again, edit the text as required and change the link to match the download link of your file.

After visitors to your site have successfully submitted the form, the thanks form will be displayed with the link to the file.

1 Comment Comment feed

Great tip! I have a client who wanted this, but didn’t want people to have to click on the link to download the file — just wanted to have it download as soon as the user submitted the form. So I worked a little magic with the great smd_if plugin.

I did this before txp:variable came around so this might be possible without the smd_if plugin …

In the article the first line of the zem_contact plugin specify the file you want to download like this:

<txp:com_connect to="your-email@example.com" redirect="/download?file=27">

Then I created a section called “download” with this code between the <head> and </head> tags:

<txp:smd_if field="urlvar:file" operator="defined">
<meta http-equiv="refresh" content="1; url=/file_download/{smd_if_file}">
</txp:smd_if>

Then, just for good measure, I put the download link down in the body of the page just in case the user’s browser doesn’t refresh:

<txp:smd_if field="urlvar:file" operator="defined">Thanks for your request. Your file download should start now. If it doesn't, please <a href="/file_download/{smd_if_file}">click Here</a>
<txp:else />
No download file was specified.
</txp:smd_if>

I’m sure this could be refined, but it seems to work well.

Add a comment

Use Textile help to style your comments