0

I have built an extension using the freeform_module_insert_end hook according to Solspace Extensions documentation as I want the form to redirect to a custom url including a unique hash - but for some reason I cannot get the hook to fire. I have pasted the code below:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Freeform Redirect Extension class
 *
 * @package        freeform_redirect
 */
class Freeform_redirect_ext {

    var $name            = 'Freeform Redirect';
    var $version         = '1.0.0';
    var $description     = 'Redirect to custom url';
    var $settings_exist  = 'n';
    var $docs_url        = '';

    var $settings        = array();

    /**
         * Constructor
         *
         * @param   mixed   Settings array or empty string if none exist.
         */
        function __construct($settings = '')
        {
            $this->settings = $settings;
        }

    /**
     * Activate Extension
     *
     * This function enters the extension into the exp_extensions table
     *
     * @see https://ellislab.com/codeigniter/user-guide/database/index.html for
     * more information on the db class.
     *
     * @return void
     */
    function activate_extension()
    {
        $this->settings = array(
            'max_link_length'   => 18,
            'truncate_cp_links' => 'no',
            'use_in_forum'      => 'no'
        );


        $data = array(
            'class'     => __CLASS__,
            'hook'          => 'freeform_module_insert_end',
            'settings'  => serialize($this->settings),
            'priority'  => 10,
            'version'   => $this->version,
            'enabled'   => 'y'
        );

        ee()->db->insert('extensions', $data);
    }


    /**
     * Disable Extension
     *
     * This method removes information from the exp_extensions table
     *
     * @return void
     */
    function disable_extension()
    {
        ee()->db->where('class', __CLASS__);
        ee()->db->delete('extensions');
    }

public function freeform_module_insert_end($inputs, $entry_id, $form_id, $obj)
{
    if ( ! $obj->edit AND
         ( ! $obj->multipage OR
            ($obj->multipage AND $obj->last_page)
         )
    )
    {
        $obj->params['return'] = 'thank-you/'.ee()->input->post('unique_hash');
    }
}

    // --------------------------------------------------------------------

} // End Class Freeform_redirect_ext

/* End of file ext.freeform_redirect.php */
6
  • Try putting in something like echo "the hook fired"; exit(); at the top of your method. If that works, the extension is firing. It may be the conditional that is the issue
    – Jim Wyse
    Commented Sep 13, 2016 at 15:27
  • you are also missing a method call to match the hook 'method' => 'freeform_module_insert_end', in your $data array.
    – Jim Wyse
    Commented Sep 13, 2016 at 15:30
  • Thanks Jim, I have added the 'method' => 'freeform_module_insert_end' to the $data array and also placed the 'hook fired' inside the public function above 'if ( ! $obj->edit AND' but there is no notice saying the hook fired. What else could I be missing here?
    – Thomas K
    Commented Sep 13, 2016 at 18:47
  • Did you make sure your extension installed properly? i. e did you look in the extensions table and see if there was an entry for it and the data is correct? I'm assuming you installed the extension. I know I'm asking the obvious questions. But that's where I would start.
    – Jim Wyse
    Commented Sep 14, 2016 at 1:56
  • Hey Jim, uninstalled and reinstalled the extension and it works now! Thanks again for helping me with this. Cheers
    – Thomas K
    Commented Sep 14, 2016 at 4:28

1 Answer 1

0

You are also missing a method call to match the hook 'method' => 'freeform_module_insert_end', in your $data array. Uninstall and reinstall the extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.