Hi,
I’ve got most of it working now! But for some reason the page goes blank once I’ve submitted the form, and then it never sends anything.
I’ve confirmed the following;
1. The eform is getting the GET field, and displays it. The form works fine!
2. All functions provided in the snippet above works fine, and it successfully grabs the file and puts it into my eform
3. If you remove the "&eformOnBeforeFormParse=`onBeforeParseFunction` &eFormOnBeforeMailSent=`onBeforeMailSentFunction`" the eform will send an email without any problems, but if you put them back in -- it never sends anything.
4. The problem is not in the functions but once its finished with the "onBeforeMailSentFunction" function.
What’s happening is that when you press "Send" on the form, it redirects to the page -- but it never displays anything. I don’t know why.
// The eform call
[[eFormEventFunctions]]
[!eForm? &eformOnBeforeFormParse=`onBeforeParseFunction` &eFormOnBeforeMailSent=`onBeforeMailSentFunction` &tpl=`downloads_form` &formid=`downloads_form` &to=`[+email+]` &toname=`[+name+]` &from=`[email protected]` &report=`download_msg` &thankyou=`thankyou_for_download` &subject=`File download request` !]
// eFormEventFunctions snippet
<?php
function onBeforeParseFunction(&$fields,&$templates){
// die("I'm inside the :" . __FUNCTION__);
global $modx;
#If no file is selected redirect to another page (with download links?)
$pageId = 35; //change to id of whatever page you want to redirect to. -- 35 is my downloads page, but this variable is never used?
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']);
/*
This is where the problems start -- up to now, everything works fine -- but once it returns
the page redirects to page 35 (via eform) -- but the page is blank. If I remove
all calls to this snippet and its functions it will redirect to page 35 with no problems and
displays a "thank you" message. So there must be a problem with the way eform handles
a redirect?
*/
return true; //process normally
}
}
function onBeforeMailSentFunction(&$fields){
// die("I'm inside the " . __FUNCTION__);
global $modx;
#is called when form is submitted succesfully
#file_id should now be in the fields array
$file = '/assets/files/'.$fields['file_id'].'.pdf';
#check that file exists
if(!file_exists($modx->config['rb_base_dir']).$file){
die("here");
$value = ($modx->config['rb_base_dir']).$file);
$fields['validationmessage']='The file requested ('.$file.') 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'] . '/assets/files/'.$fields['file_id'].'.pdf';
$fields['download_url'] = $url;
return true;
}
}
?>
And finally, the actual form
<br clear="all" />
<div id="validationmsg">[+validationmessage+]</div>
<form method="post" action="/[~[*id*]~]" id="downloads_form">
<input type="text" name="file_id" value="[+file_id+]" />
<input type="hidden" name="formid" id="formid" value="downloads_form" />
<p>
<label for="name">Name:</label><br />
<input type="text" name="name" id="name" maxlength="50" eform="Your name::1" />
</p>
<p>
<label for="email">Your email address:</label><br />
<input type="text" id="email" name="email" maxlength="40" eform="Your Email Address:email:1" />
</p>
<p>
<input id="button" type="submit" class="submit" name="Submit" value="Send" />
</p>
</form>
So in summary;
When I press submit, it process everything fine -- then it redirects to page 35 and then the page goes blank. No error messages, nothing. If however I remove all calls to the "eFormEventFunctions" the eform sends an email, thank you message, etc without any problems.
What am I doing wrong?