-
Hooks dont fire
Dear All,
Recently I started working with contao as CMS and this would be the first time I used a hook. But somehow I don't seem to get it working. It looks like the hook is never triggerd by the event. I assume I missed something. :)
Ok, lets give you what i have got so far:
vacaturebank/config/config.php
Code:
<?php if (!defined('TL_ROOT')) die('You cannot access this file directly!');
//Back-end
array_insert($GLOBALS['BE_MOD']['content'], 3, array(
'vacaturebank' => array(
'tables' => array('tl_vacaturebank'),
'icon' => 'system/modules/vacaturebank/html/icon.png'
)
));
//Front-end
array_insert($GLOBALS['FE_MOD']['vacaturebank'], 0, array(
'vacaturebank' => 'ModuleVacaturebank',
'vacaturebank detail' => 'ModuleVacaturebankDetail',
'vacaturebank soliciteren' => 'ModuleVacaturebankSoliciteren',
'vacaturebank overzicht FE' => 'ModuleVacaturebankOverzicht',
'vacaturebank nieuwe vacature FE' => 'ModuleVacaturebankNieuweVacature',
'vacaturebank bewerk vacature FE' => 'ModuleVacaturebankBewerkVacature'
));
//CSS
$GLOBALS['TL_CSS'][] = 'system/modules/vacaturebank/html/vacaturebank.css';
//hook
$GLOBALS['TL_HOOKS']['processFormData'][] = array('Vacaturebank_lib', 'SendMail');
//Javascript
//$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/vacaturebank/html/vacaturebank.js';
?>
vacaturebank/Vacaturebank_lib.php
Code:
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
class Vacaturebank_lib extends System
{
public function SendMail($arrPost, $arrForm, $arrFiles, $arrLabels)
{
$email = new Email();
$email->subject = 'JOEPIE';
$email->html = 'poepje';
$email->sendTo('f.c.martin@student.tue.nl');
}
}?>
Also a template file, in which the form is that i need to process is:
vacaturebank/templates/mod_vacaturebank_soliciteren.html
Code:
<form name="soliciteren" action="solliciteren.html?id=<?php echo $this->vid; ?>" method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token::*}}">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
<input type="hidden" id="send" name="send" value="1" />
<input type="hidden" id="id" name="id" value="<?php echo $this->vid; ?>" />
<input type="submit" class="button" value="Verstuur sollicitatie" />
</form>
I have considered to use the default form generator, but unfortunately i cannot achief the desired result with the formgenerator. (As i need to send the form to a email from the database including an attachment) Also a bunch of other files are included in this module but i dont think these are relevant.
I would appriciate it much if someone would look at this.
Kind regards,
Frank
-
Re: Hooks dont fire
The processFormData hook fires only with forms handled by Contao (i.e. forms created with the form generator)
What are your needs?
Why are you telling you can't use the form generator?
-
Re: Hooks dont fire
That explains a lot.
The problem is that the vorm ( with attachment ) needs to be send to a emailadress that need to be fetched from the database depending on the user input. As the form generator only support sending it to a fixed email I had to make a custom form, this works fine... But I cannot fetch the attachment ( as $_FILES is not available )
What would be a good solution? Enter a 'fake' email in the form generator and also fetch the email adres in the procesform hook?
-
Re: Hooks dont fire
if you are using Contao 3.x there is the (undocumented) prepareFormData hook
https://github.com/contao/core/blob/.../Form.php#L256
-
Re: Hooks dont fire
I am using 2.11.. I could update to 3 but do you have any other suggestions?
Thanks for your help so far!
-
Re: Hooks dont fire
not sure about this but maybe you can change the e-mail value in the validateFormField hook
-
Re: Hooks dont fire
You can create any form you need with the normal form generator, then use the processFormData hook to do whatever processing you need, including changing the recipients. Look at the extension efg that does this for both Contao 2 and 3.
in config.php they say: $GLOBALS['TL_HOOKS']['processFormData'][] = array('Efp', 'processSubmittedData'). The referenced function handles sending the e-mail just as the Contao core functions would. Efg added a field to tl_form where you can select that the form should be handled by Efg or not. This way you can add your custom processing (but need to process the entire form) and still leave default behavior intact if you need it.
ps, it should be 'poepie'...
-
Re: Hooks dont fire
@Ruud
the processFormData hook fires after the email has been sent both in Contao 3.x and Contao 2.x
https://github.com/contao/core/blob/.../Form.php#L253
-
Re: Hooks dont fire
@ga.n that is not relevant if you did not check "send e-mail" in the form settings. You can then do your own sending. (which you could turn on/off with a new field added to tl_form)
-
Re: Hooks dont fire
sorry i did not understand you are talking about implement your own sending.