Results 1 to 10 of 10

Thread: Hooks dont fire

  1. #1
    New user
    Join Date
    04-17-13.
    Posts
    3

    Default 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

  2. #2
    User
    Join Date
    06-19-09.
    Posts
    328

    Default 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?
    Consulenza Contao CMS https://www.intco.it

  3. #3
    New user
    Join Date
    04-17-13.
    Posts
    3

    Default 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?

  4. #4
    User
    Join Date
    06-19-09.
    Posts
    328

    Default 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
    Consulenza Contao CMS https://www.intco.it

  5. #5
    New user
    Join Date
    04-17-13.
    Posts
    3

    Default 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!

  6. #6
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: Hooks dont fire

    not sure about this but maybe you can change the e-mail value in the validateFormField hook
    Consulenza Contao CMS https://www.intco.it

  7. #7
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default 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'...

  8. #8
    User
    Join Date
    06-19-09.
    Posts
    328

    Default 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
    Consulenza Contao CMS https://www.intco.it

  9. #9
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default 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)

  10. #10
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: Hooks dont fire

    sorry i did not understand you are talking about implement your own sending.
    Consulenza Contao CMS https://www.intco.it

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •