This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Collect data before downloading file?


  1. markritchie
    Member

    I am wondering if anyone has any ideas on how I could use MachForm to collect information before a file is downloaded. I have a download script that integrates an html form within the code. The user fills out a form before they are allowed to download a file.

    I'd like to somehow use Machform to do this so that their details are stored in the backend with the rest of my forms. I know Machform is not a download script but I'm asking if anyone has any ideas!

    I have thought about creating a seperate form for each download and then routing them to a URL with some sort of antileech script to download the file however...if I have 20 files or more then thats alot of forms to create and manage.

    The download script I have uses one form only then calls the file to be downloaded by inserting a link such as: http://www.mywebsite.com/download.php?paper=The FILE TO BE DOWNLOADED

    Basically the whole idea is:

    1.) User wants to download file and clicks link
    2.) User fills out form
    3.) User is granted access to hidden download after sending form
    4.) Users details are sent to Machform specifying their details in the form as well as which file they downloaded.

    Anyways..just thought I'd ask in case anyone has some ideas!

    Mark

    Posted 15 years ago #
  2. markritchie
    Member

    Well it's been a bit and checked this post. Surprisingly nobody replied :(

    I've been doing A LOT of google searching on "filling out form before file download" etc but no luck. There are a lot of anti-leech scripts I could use but this doesnt stop users from going to my site and then entering the URL to download the file bypassing the form.

    Basically I need something that if people go to a certain URL (the file download link)they are automatically routed to my form to fill it out before download is allowed.

    Does anyone know of a script I could incorporate into my site to accomplish this?

    Thank you for any ideas (I really need them),

    Mark

    Posted 15 years ago #
  3. redityo

    Hi Mark,

    Sorry for late response, anyway from your basic idea :

    1.) User wants to download file and clicks link
    2.) User fills out form
    3.) User is granted access to hidden download after sending form
    4.) Users details are sent to Machform specifying their details in the form as well as which file they downloaded.

    I think you can put the download script on "success page" after user fill out the form. But it need some hack to do if your files is dynamic. Anyway I'm not sure with some point :

    1. All user will be grated to download the form after fill out the form
    2. Downloaded file will refer to some field in machform form ? ex : user select A will get file A ?


    MachForm Support

    Posted 15 years ago #
  4. markritchie
    Member

    Hello and thanks for the response!

    I do have a download script in place now so that if a user tries to go directly to the file they are sent to the forms page. The only set back I am having is as you say:

    2. Downloaded file will refer to some field in machform form ? ex : user select A will get file A ?

    Right now I create a form for each file...I would much rather use a single form. However I don't want to make the end user select from a drop down box which file they want to download etc..

    The way the download script I have right now is like this:

    I created single thankyou.php page which has the following in it:

    <?php
      session_start();
      $_SESSION['token'] = 'mytokenvalue';
    ?>
    <div>Your download will begin shortly. Thank you for your submission</div>
    <meta http-equiv="refresh" content="2;url=http://www.mysite.com/download.php?file=<?php echo $_GET['file']; ?>">

    In the download settings of the download script I set an array for example:

    'MY FILE' => array(
    		'filename' => 'ACTUAL FILE NAME.ZIP.PDF ETC.',

    I do the above step for each file to download. Then in Machform for the success message I select "Redirect URL". I then route them to (using the example from the array above) thankyou.php?file=MY FILE

    The thank you message from thankyou.php is shown and the file is served. So is there something I could input into a sinlge form that would show in the "View entries" of machform which file a user downloaded?

    Thanks for any ideas!

    Mark

    Posted 15 years ago #
  5. redityo

    Hi Mark,

    Maybe you can look at to this post :

    http://www.appnitro.com/forums/topic/conditional-redirect-url

    It use some condition refer to the form field to give a redirect url when submit the form. So the user will get an url to download the file after fill out your form. Is that what you looking for ?


    MachForm Support

    Posted 15 years ago #
  6. markritchie
    Member

    Hmmm not quite. I don't want to have check boxes, etc. to make the user select which file they download. I automatically route them to the file download via the download script (for example)

    thankyou.php?file=MY FILE

    I am wondering if there is a way to input into the View Entries "which" file the user downloaded. Possibly using a hidden field perhaps? And within the hidden field that particular field would be auto filled in with the the file the user downloaded.

    Perhaps there is a way to auto fill the hidden field by the way I link to the form?

    Does that make sense?

    Thanks,

    Mark

    Posted 15 years ago #
  7. redityo

    I'm still wonder where "MY FILE" variable come from ? I'm trying to figure out your requirement like this :

    1. You have a download link to your file. For example :

    http://www.mywebsite.com/download.php?paper=file1.pdf

    (after click that link you will redirect to the machform form)

    2. You have a machform form, with url :

    http://www.mywebsite.com/form.php

    (Save GET "paper" variable to one of machform field -- admin field)

    3. After submit the form, you will be redirect to download script based on saved value in machform field. For example download script is :

    http://www.mywebsite.com/download_script.php?paper=file1.pdf

    ("file1.pdf" come from machform field)


    MachForm Support

    Posted 15 years ago #
  8. markritchie
    Member

    Hi redityo and thanks for your help in this matter. This will be a long post but hopefully when I am done you will have a full understanding of my situation.

    Basically from the start, I have a script to force a user to fill out a form before they are allowed to download any files. The download script includes the following:

    download.php
    includes/downloadfunctions.php
    includes/downloadsettings.php

    In the downloadsettings.php file I specify my arrays for the file names.

    $SETTINGS = array(
    	'path_to_files' => 'downloads/',
    
    	//start files. 'filename' is the actual filename. Note: no comma after the last ")"
    
    	'file1' => array(
    		'filename' => 'something.pdf',
    		),
    	'file2' => array(
    		'filename' => 'somethingelse.zip',
    		),
    	'file3' => array(
    		'filename' => 'random.zip',
    		),
    	'file4' => array(
    		'filename' => 'checkitout.pdf',
    		)
    	);

    I create a thankyou.php page with the following:

    <?php
      session_start();
      $_SESSION['token'] = 'mytokenvalue';
    ?>
    <div>Your download will begin shortly</div>
    <meta http-equiv="refresh" content="2;url=http://www.mysite.com/download.php?file=<?php echo $_GET['file']; ?>">

    I then create a form in Machform which I want users to fill out before they are granted access to the file they want to download. Using an example from above in the downloadsettings.php file lets say this form is for:

    'file3' => array(
    		'filename' => 'random.zip',

    So I create my form. Let's call the form "file3 download". For the success message I route them to a URL (the thankyou.php file). So now the download script needs to know which file the user wants to download. To accomplish this I specify extra information in the link so for "file3" my success URL would look like this:

    thankyou.php?file=file3

    So let's see it in action.

    A user wants to download "random.zip".
    I specify a link on my site to the "file3 download" form
    User fills out the form
    Upon sumission they are routed to thankyou.php?file=file3
    The success message I specified in thankyou.php is shown. In my above example it is:

    <div>Your download will begin shortly</div>

    The download dialog box pops up to download "random.zip" Which is "file3" in downloadsettings.php

    Okay so far so good. So lets say a user wants to download "something.pdf" which is "file1" in downloadsettings.php. The way I am accomplishing this now is I create "another" form in machform. Let's call this one "file1 download". For the success message I route them to the thankyou.php page only this time I need to tell the script we want "file1" so my success URL for this form would be:

    thankyou.php?file=file1

    And on and on I create a seperate form for "each" file. This works fine however I would like to use just ONE download form for all file downloads. This is where I am stuck. Using the above method I know who downloads what file because each file has it's own form (ie file3 download, file1 download)

    Is there a way I would be able to use just one form without using "checkboxes" or "dropdowns" in my form?

    The following is what I am thinking but I do not know how at this point:

    So let's say I have a single form for all file downloads and let's place it at www.mysite.com/filedownload.php. Within the form there is a "hidden" field.

    Now lets say a user wants to download "file1"

    I am thinking it may be possible of adding something to the machform code that tells machform basically

    "Hey, if the URL ends with "file1" then autopopulate the hidden field in the form and send them to the correct thankyou.php URL to download the file"

    So maybe for "file1" I could link to my form like this:

    www.mysite.com/filedownload.php?field=file1

    Then within the Machform code I would need to modify something to tell Machform

    "Hey, the user clicked on a link with file1 attached to the end. Autopopulate the hidden field with "file1" and when they submit the form send them to thankyou.php?file=file1"

    OR (for another file)

    "Hey, the user clicked on a link with file3 attached to the end. Autopopulate the hidden field with "file3" and when they submit the form send them to thankyou.php?file=file3"

    Then in the admin interface of Machform I could see who is download what file using one form instead of 20 (1 for each file)

    Okay what a post! (whew) "Hopefully" you understand a bit better of what I am trying to accomplish and as usual appreciate any ideas you may have!

    Thanks a lot,

    Mark

    Posted 15 years ago #
  9. redityo

    Hi Mark,

    Sorry to be unclear :) .. I got it now, you can try these steps. Let's say you've create form with id = 37 and put a field (will be a hidden field to store file information) with id = 2. First your download link will be like this :

    1. http://www.yoursite.com/filedownload.php?file=book.pdf

    I think you will embed machform code in there, something like this :

    <iframe height="352" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none"
    src="http://www.yoursite.com/machform/embed.php?id=37" title="Untitled Form">
    <a href="http://www.yoursite.com/machform/view.php?id=37" title="Untitled Form">Untitled Form</a>
    </iframe>

    to populate file information from download link, you need to replace the embed code to be like this :

    <iframe height="352" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none"
    src="http://www.yoursite.com/machform/embed.php?id=37&file=<?php if (!empty($_GET['file'])) {echo ($_GET['file']);} ?>" title="Untitled Form">
    <a href="http://www.yoursite.com/machform/view.php?id=37" title="Untitled Form">Untitled Form</a>
    </iframe>

    2. Edit your "view-functions.php" and go to line 40, you will see this :

    $element_markup = <<<EOT

    put these code above that line

    if ($_GET['id'] == 37 && $element->id == 2) {
    	$element->default_value = $_GET['file'];
    }

    3. Edit "post-functions.php" and go to around line 180, you will see this :

    }elseif ('textarea' == $element_type){ //Paragraph

    put above that line

    $redirect_file = '';
    if ($form_id ==  37 && $element_id == 2) {
    	$redirect_file =  $element_data;
    }

    4. Edit "post-functions.php" and go to line 879, you will see this :

    $process_result['error_elements'] = $error_elements;

    Put these code below that line

    if ($redirect_file != '') {
    	$process_result['form_redirect'] = "http://www.yoursite.com/thankyou.php?file=" . $redirect_file;
    }

    4. And the last, to hidden the field. You need to edit your "CSS" form, put these style in there :

    #li_2
    {
    display:none !important;
    }

    make sure you change the ID's in my example code.

    Hope this help..


    MachForm Support

    Posted 15 years ago #
  10. markritchie
    Member

    Hey and thanks for the help! The one thing I didn't specify in my post above was that I am using the advanced code to place the form. Would you mind telling me what your iframe code should look like using the advanced code?

    The code I have right now is:

    <?php
    	require("/usr/local/apache2/htdocs/forms/machform.php");
    	$mf_param['form_id'] = 6;
    	$mf_param['base_path'] = 'http://mysite.com/forms/';
    	display_machform($mf_param);
    ?>

    Thanks A LOT!!!!

    Mark

    Posted 15 years ago #
  11. redityo

    Hi Mark,

    I see.. My previous code in point 1 and 2 need to be updated then :

    1. For form embed code

    <?php
    	require("/usr/local/apache2/htdocs/forms/machform.php");
    	$mf_param['form_id'] = 6;
    	$mf_param['base_path'] = 'http://mysite.com/forms/';
    	display_machform($mf_param);
    ?>

    You can change with this

    <?php
    	@session_start();
    
    	unset($_SESSION['file']);
    	if (!empty($_GET['file'])) {
    		$_SESSION['file'] = $_GET['file'];
    	}
    
    	require("/usr/local/apache2/htdocs/forms/machform.php");
    	$mf_param['form_id'] = 6;
    	$mf_param['base_path'] = 'http://mysite.com/forms/';
    	display_machform($mf_param);
    ?>

    2. Update my code in point 2, from :

    if ($_GET['id'] == 37 && $element->id == 2) {
    	$element->default_value = $_GET['file'];
    }

    to

    if ($element->id == 2 && (!empty($_SESSION['file']))) {
    	$element->default_value = $_SESSION['file'];
    }

    MachForm Support

    Posted 15 years ago #
  12. Markstein
    Member

    Hello redityo, it has been awhile but I am finally getting around to doing this. (Was ill for quite some time)

    I was entering the code you provided into the files you specified above however I do not have the line:
    $process_result['error_elements'] = $error_elements;
    anywhere near line 79 in post-functions.php. You had stated in point 4 above

    4. Edit "post-functions.php" and go to line 79, you will see this :

    $process_result['error_elements'] = $error_elements;

    Put these code below that line

    if ($redirect_file != '') {
    	$process_result['form_redirect'] = "http://www.yoursite.com/thankyou.php?file=" . $redirect_file;
    }

    Any ideas here? I haven't modified anything other than what you stated in your post above!

    Thanks a million!

    Mark

    Posted 14 years ago #
  13. Markstein
    Member

    Hope you don't mind me bumping up my topic here. This is the last thing I need to finish before completing my site.

    The following shows my search for $process_result['error_elements'] = $error_elements;

    machform\includes\post-functions.php (4 hits)
    
    Line 882:     $process_result['error_elements'] = $error_elements;
    Line 903:     $process_result['error_elements'] = $error_elements;
    Line 919:     $process_result['error_elements'] = $error_elements;
    Line 1990:    $process_result['error_elements'] = $error_elements;

    Thanks for your much needed advice!

    Mark

    Posted 14 years ago #
  14. redityo

    ups .. sorry, I mean the line code is around line "879". I think in your code should on line "882"


    MachForm Support

    Posted 14 years ago #
  15. Markstein
    Member

    Thanks redityo for your continued help. I have modified all my files and have been testing. The only problem is when I create a link to my download for example:

    http://www.mysite.com/form-pages/filedownload.php?file=TTI-Award

    I am not getting the file but instead getting prompted to download "download.php"

    In my machform form properties I set the success message to redirect to url which in my case is "thankyou.php"

    Another problem is when I go to view the entries it is not telling me which file was downloaded.

    Ugh..I am in over my head but I feel it is almost there! Any ideas on what could be happening?

    Thank you very much,

    Mark

    Posted 14 years ago #
  16. Markstein
    Member

    Hmm okay perhaps I am confused on what I should be entering for the "success message" of my form.

    As it is right now I have it aimed at my "thankyou.php" which calls the download script: The contents of thankyou.php are as follows:

    <?php
      session_start();
      $_SESSION['token'] = 'mytokenvalue';
    ?>
    <div>Your download will begin shortly</div>
    <meta http-equiv="refresh" content="2;url=http://www.mysite.com/new/download.php?file=<?php echo $_GET['file']; ?>">

    My link for the success url is:

    http://www.mysite.com/new/form-pages/thankyou.php

    I tried this thinking it may work but it did not:

    http://www.mysite.com/new/form-pages/thankyou.php?file=<?php echo $_GET['file']; ?>

    I have also went back and verified that all coding is correct (ie. form id, label id, url's etc.

    If it would help..I can type out everything I have done like I did above with all of the actual URL's etc and send it to you through the support ticket system. Please let me know!

    Thank you,

    Mark

    Posted 14 years ago #
  17. Markstein
    Member

    Hello Appnitro Team,

    I understand that this post is not a Machform support issue but rather a "customization" which I cannot expect you to help me with. I am beyond grateful that redityo has taken his time to attempt to help me out this far. I would really like to make this work and am wondering if perhaps you wouldn't mind doing this customization for a fee. Please do let me know and thank you for your consideration.

    Mark

    Posted 14 years ago #

RSS feed for this topic

Reply