Customize the RSFiles! email download form with RSForm!Pro

in RSForm!Pro, RSFiles! on 03 Sep 2015 having 0

By default RSFiles! can send file download links via email (users fill out a form and upon submit an email is sent). But, what if you want to change the email download form with a custom one? Well, through RSForm!Pro, though no particular integration, this would be possible.

RSFiles!-RSForm!pro-email-download
Intro

RSFiles! allows sending download links to your files via email. Before doing so, a form is presented to the user to fill details such as name and email. You might want additional details or to provide extra functionality under this email download form.

We'll discuss about replacing the RSFiles! email download form with a custom one made through RSForm!Pro.

Steps & Setup Path

Quick steps navigation is listed below:

The tutorial was made using RSForm!Pro version 1.50.22 and RSFiles! version 1.15.4.

Quick download: you can download the form backup (that you can restore through the RSForm!Pro - Restore Backup feature) and the template override file:

override file form backup

Important: after you've restored the form, you'll have to re-create the mapping as instructed in this blog post and delete the one that comes with the backup (this won't work as you'll most likely have an entirely different database prefix).

Form Creation

If you're new to RSForm!Pro, you can checkout the Getting Started section for a better understanding on creating a form.

We're going to start by adding regular form elements such as:

Note - this scenario assumes the following field naming (case sensitive):
  • field type - name
  • textbox - email
  • textbox - name
  • hidden field - ip
  • hidden field - path
  • hidden field - Itemid
Perform Template Override

A template override is required for the "\components\com_rsfiles\views\rsfiles\tmpl\email.php" file, which loads the standard RSFiles! emails download form. Firstly, create the file duplicate that will be used as template override:

  1. Copy:
  2. \components\com_rsfiles\views\rsfiles\tmpl\email.php
  3. Paste (final file destination):
  4. \templates\protostar\html\com_rsfiles\rsfiles\email.php
Note:

In this example, the standard Joomla! Protostar template was used. Remember to replace protostar with your actual template folder name. A more detailed explanation on how to override the output from the Joomla! core.

Override Adjustments

The "email.php" contents should be similar to:

Override email.php file contents click to expand
 
<?php
/**
* @package RSFiles!
* @copyright (C) 2010-2014 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
 
<?php //File related details 
$ip    = rsfilesHelper::getIP(true);
$md5Ip  = md5(uniqid($ip));
$path   = base64_encode($this->path);
$Itemid = $this->itemid; ?>
 
<!-- passing information within hidden fields -->
<input type="hidden" id="h-ip" value="<?php echo $md5Ip; ?>">
<input type="hidden" id="h-path" value="<?php echo $path; ?>">
<input type="hidden" id="h-Itemid" value="<?php echo $Itemid; ?>">
 
<!-- our form, replace `3` with your form ID -->
<div style="width:300px;">{rsform 3}</div>
 

We're basically creating hidden fields to include information that will be further captured by RSForm!Pro. You'll have to change '{rsform 3}', the number 3, with your form exact ID (found via backend > Components > RSForm!Pro > Manage Forms > here, within the provided table listing, last column on the right).

RSForm!Pro - System Plugin

In order for this specialized placeholder {rsform 3} to work, in this case, the "RSForm!Pro - System Plugin" plugin is required. This can be downloaded via our website and normally installed through the standard backend Joomla! installer (afterwards, via Plugin Manager, check if the plugin is enabled).

Up until this point, if you're trying to download a file through RSFiles! which has Email Download selected as the Download method, your custom form should be open in a pop-up/lightbox instead.

Capturing RSFiles! specific file details (JavaScript)

Each form you make with RSForm!Pro has its own scripting areas, including a JavaScript one (while editing a form > Properties > CSS and JavaScript > JavaScript). You can use (including the <script> tags) a similar script to capture RSFiles! data from the hidden fields added through template overrides in our form's hidden fields: JavaScript example click to expand


 
<script type="text/javascript">
window.onload = function(){
  //the following array stores our hidden fields names in order to iterate their data.
  //similar IDs were given for the template override hidden fields and the form hidden fields in order for this to work. 
  var hiddenArray = ['ip','path','Itemid'];
  for(var i=0; i < hiddenArray.length; i++){
    document.getElementById(hiddenArray[i]).value =
    document.getElementById('h-'+hiddenArray[i]).value;
  }
}
</script>
 
Construct User Email (PHP)
Start by configuring the User Email (while editing a form > Properties > User Emails). A more in-depth explanation on setting up RSForm!Pro emails here. Once the email is setup, within the User Email body, you can add a link like so (if you're using an editor, switch to the view source code mode in order to add HTML code):
 
<a href="[fileLink]" target="_blank">download file!</a>
 
Notice [fileLink], this doesn't quite actually exist. We're using it as a unique string which will be replaced by the following PHP script. Navigate to the form's Properties > PHP Email Scripts and within the "Script called before the User Email is sent" area, add: User Email PHP script click to expand
 
//capturing hidden fields details
$hash = $_POST['form']['ip'];
$path = $_POST['form']['path'];
$Itemid = $_POST['form']['Itemid'];
 
//our custom "placeholder"
$fileLink = '[fileLink]';
 
//generating file download link
$finalLink = JRoute::_(JURI::root().'index.php?option=com_rsfiles
&task=rsfiles.download&path='.$path.'&email=1&emailhash='.$hash.$Itemid,false);
 
//replacing our placeholder with the file download link
$modUserEmailText = $form->UserEmailText;
$modUserEmailText = str_replace($fileLink,$finalLink,$modUserEmailText);
$userEmail['text'] = $modUserEmailText;
$userEmail['text'] = str_replace($placeholders, $values, $userEmail['text']);
 
Insert data into RSFiles! (RSForm!Pro Mappings)

RSForm!Pro built-in feature, Mappings, allows performing database Insert, Update, Delete queries through a user friendly interface for those who aren't code savvy.

When a file is downloaded, RSFiles! normally captures details on this event for future validations. We're going to replicate this through RSForm!Pro Mappings.

Access the Mappings panel (while editing a form > Properties > Mappings) and specify mappings as so:

  1. Click on the 'New Query' button.
  2. Set 'Connection type' to "Local".
  3. Set 'Method' to "Insert".
  4. Click on the 'Connect to database' button.
  5. From the 'Database table' dropdown select "#__rsfiles_email_downloads".
    (`#` would be your Database Tables Prefix)
  6. Leave 'id (int) empty as this is an auto-incremented integer.
  7. Set 'hash (varchar)' to {ip:value}
  8. Set 'date (datetime)' to {global:date_added}
    (this is a global placeholder and it will be replaced with the submission date/time).
  9. Set 'email (varchar)' to {email:value}
  10. Set 'name (varchar)' to {name:value}
  11. Finally, click on the "Save & Close" button.
(optional) Thank You Message

Let's assume we want to show a "thank you message" after users submit the form. You can do so under the following setup (while editing a form > Properties > Form Info):

  • enable the "Show Thank You Message" option.
  • click on the "Edit the Thank You Message" button to add your desired thank you note.

By default a "Continue" button is provided on the Thank You Message page, which refreshes the page showing your form once again. You can leave it enabled, or you can replace it with a pop-up closing button instead:

  • disable the "Show Continue Button" option.
  • navigate to "PHP Scripts" tab and within the "Script called after form has been processed" area, use:
 
$thankYouMessage .= '<input type="button" class="rsform-submit-button btn btn-primary" name="close" 
value="Close!" onclick="window.parent.SqueezeBox.close();">';
 
RSJoomla! Community

You can shape the future RSJoomla! development! Feedbacks can be added here, and you can join the community forum area to discuss your opinions.

How to get it

Access to the downloads section of RSFiles! or RSForm!Pro is granted to users that own an active subscription. If you are in need of a subscription, you can purchase one from the product page - RSForm!Pro, RSMail!.

Expired subscriptions can be renewed with a 30% discount (this discount is applied automatically).

A 15% discount is granted when purchasing two or more new subscriptions in one go (this discount is applied automatically).

buy - RSForm!Pro buy - RSFiles!



Subscribe to our blog

Found this article interesting? Subscribe to our blog for more.

1000 Characters left

Antispam Refresh image Case sensitive