give name/email for download a file

alfredopacino 30 Oct, 2014
Hi, this thread is mainly for pick up some advices for the development.
As in title, I want to give the user the possibility of download files but they have to fill a 2 field form (name/email).
What's the problem?
The form is placed in some article (using chronoform plugin) and each article has its file.
Make a new form for each article is against the IT principles😀
How do you think can I do that?
GreyHead 31 Oct, 2014
Hi alfredopacino,

Please see this FAQ that should let you get the current article id or title and then you can use that to look up the matching file and build a link to it.

Bob
alfredopacino 31 Oct, 2014
are you suggesting something like
$id = JRequest::getInt('id', '');
switch($id){
 case 10:
        $url="/file.zip";
        break;
    case 111:
        $url="/file.zip";
        break;}


or something different (or better)?😉
GreyHead 01 Nov, 2014
Hi alfredopacino,

A switch will work fine but is a bit hard to update if anything changes. I'd probably use something like this:
<?php
$files_array = array(
  10 => 'file_a.zip',
  111 => 'file_b.zip',
  . . .
);
$form->data['form'] = '';
if ( isset($form->data['id']) && intval($form->data['id']) > 0 && array_key_exists($form->data['id'], $forms_array) {
  $form->data['form'] = JURI::root().'some_path/'.$forms_array[$form->data['id']];
}
?>
Then if you add an article you only need to add a new array entry,

Or you could save the file info in a database table and look it up from there. That works better if there are frequent changes as you can build a CC List and a CC Form to manage the list.

Bob
alfredopacino 01 Nov, 2014
I've not tried yet, but what's $form->data['id'] ?
I need the article id, is that it?
GreyHead 02 Nov, 2014
Hi alfredpcino,

It's the same as the JRequest line in your code. If there is an id parameter in the URL then ChronoForms will add it to the $form->data array.

Bob
This topic is locked and no more replies can be posted.