Maybe if I make it easier to understand I can get a quick answer.
On the site you have downloadable PDFs (assets/files/somefile.pdf)
The site lists them somewhere.
Before you can download the file you must fill in a form, the form asks for your name and email.
An email message is sent to you, firstly thanking you for your request and providing you a hyperlink to where you can download the file.
How does one achieve these goals?
<form action="eformaction" method="post" accept-charset="utf-8"> <p> <input type="hidden" name="property_pdf" value="property_pdf" id="some_name"></p> <p><input type="submit" value="Download File"></p> </form>
<a href="downloadform.html?file_id=somefile">Some File</a>
<input type="hidden" name="file_id" value="[+file_id+]" />
[[eFormEventFunctions]] [!eForm? &eFormOnBeforeParse=`onBeforeParseFunction` &eFormOnBeforeMailSent=`onBeforeMailSentFunction` ... ret of params ]]
<?php
function onBeforeParseFunction(&$fields,&$templates){
global $modx;
#If no file is selected redirect to another page (with download links?)
$pageId = 1; //change to id of whatever page you want to redirect to.
if(!isset($_REQUEST['file_id'])){
$modx->sendRedirect($modx->makeUrl($pageId));
return false;
}else{
#store file_id in form so it propagates
$templates['tpl'] = str_replace('[+file_id+]',$_REQUEST['file_id'],$templates['tpl']);
return true; //process normally
}
}
function onBeforeMailSentFunction(&$fields){
#is called when form is submitted succesfully
#file_id should now be in the fields array
$file = 'files/'.$fields['file_id'].'.pdf';
#check that file exists
if(!file_exists($modx->config['rb_base_dir']).$file){
$fields['validationmessage']='The file you requested does not or no longer exists!';
return false;
}else{
#Get the url belonging to file_id and store in fields array
# In your report template place a [+download_url+] place holder
$url = $modx->config['rb_base_url'] . 'files/'.$fields['file_id'].'.pdf';
$fields['download_url'] = $url;
return true;
}
}
?>
// This is what appears on the page template
[[eFormEventFunctions]]
[!eForm? &eFormOnBeforeParse=`onBeforeParseFunction` &eFormOnBeforeMailSent=`onBeforeMailSentFunction` &formid=`downloads_form` &tpl=`downloads_form`!]
// Downloads is a page // press release is a PDF <a href="/downloads?file_id=Press_release">Some File</a>
// Downloads form chunk <form method="post" action="/[~[*id*]~]" id="form"> <input type="text" name="file_id" value="[+file_id+]" /> <!-- it should put the value of the file in here, but it doesn't display anything --> <input type="hidden" name="formid" value="download_form" /> </form>
[[testy]] // force output the $REQUEST [[eFormEventFunctions]] // do the functions [[testy2]] // force output the contents of $templates, $fields, etc. [!eForm? stuff... !]
<?php print "<br />TEMPLATE DATA: " . $templates; print_r($templates); print '<br />'; print "<br />TEMPLATE DATA2: " . $template; print_r($template); print '<br />'; print "FIELDS: ". $fields; print_r($fields); ?>