1

I am a .NET/Java developer so I'm not very familiar with PHP although I have dabbled with it in the past and am a total noob with Expression Engine. I am working on a project at work along side our front-end site developer who is using EE to build a membership site. We are using FreeForm Pro to create 2 or 3 user forms.

The first is a simple form asking for first name, last name and email address. When the user supplies this information and clicks the submit button we want to be able to verify the person's existence in a table that was not created by the installation of the FreeForm module. At the moment I copied the basic form code example from FreeForm documentation pages and pasted it to a Template in EE:

<h3>Contact Us</h3>
<p>
    To send us a message, please fill out the form below.
    We’ll get back to you shortly!
</p>

{exp:freeform:form
    form_name="contact"
    return="contact_us/thank_you"
}
    <dl>
    {freeform:all_form_fields}
        <dt><label>{freeform:field_label}</label></dt>
        <dd>{freeform:field_output}</dd>
    {/freeform:all_form_fields}
    </dl>
    {if freeform:captcha}
        <p>Please enter the word you see in the image below:</p>
        <p>{freeform:captcha}<br />
        <input type="text" name="captcha" style="width:140px;" /></p>
    {/if}
    <p>{freeform:submit}</p>
    {if freeform:no_results}
        <p>
            Specified form was not found. Please make sure you have
            specified the correct short name of the form in the
            <b>form_name</b> parameter.
        </p>
    {/if}
{/exp:freeform:form}

When submit button on this form is clicked the data gets saved into the table exp_freeform_form_entries_1. This is unnecessary for us but not a big deal. What we want to do is verify with a table that was not created by the FreeForm module like a membership_staging table to determine if the person is already registered. The membership_staging table is a table that was imported from another application.

We were thinking we could use one of the extension hooks like freeform_module_insert_begin to redirect the forms functionality to do a simple query and comparison to the membership_staging table but are have not been able to figure out how the hooks are triggered and how to use them correctly. I copy/pasted the following hook code from the FreeForm documentation into my EE Template.

if (ee()->extensions->active_hook('freeform_module_insert_begin') === TRUE)
{
    $field_input_data = ee()->extensions->universal_call(
        'freeform_module_insert_begin',
        $field_input_data,
        $entry_id,
        $form_id,
        $this
    );

    if (ee()->extensions->end_script === TRUE)
    {
        return;
    }
}

I am not sure if this piece of code is being executed when the submit button is clicked and have no idea how to test if it is. I have scoured the internet for the past week looking for tutorials or examples of how to utilize hooks in an EE template but only find tutorials and example on how to build extensions and none of them talk about hooks and how to use them.

I would greatly appreciate it if someone could assist me in filling in the blank.

0

You need to write what's called an extension.

https://ellislab.com/expressionengine/user-guide/development/extensions.html

Basically, an extension fires when a given hook goes by, you can do your check in the aux table there, and then return to the form submission.

The Freeform docs show what hooks are available to work with.

| improve this answer | |
  • As I mentioned I do know where to find all the hooks for FreeForm Pro in their docs. I even copy/pasted it in my question. I've already read the EE Extentions Development docs. I wasn't asking where to find those. I was asking how to use the the hook for FreeForm. I am not sure what aux table you talking about but we already have a reference table that was imported into EE from a third party application that we need to verify against. You totally missed my question. – iJared Oct 2 '15 at 23:48
  • solspace.com/software/expressionengine/freeform/docs/… It's the link labeled "Extension Hooks". – Jim Wyse Oct 3 '15 at 1:19
  • Jim I am not going to mark your answer as an answer if you don't read my entire question. If you did you would see that I've already been to that page since I have code from that page copy/pasted into my question. How about you don't come back to my questions and let someone with a real answer post something. – iJared Oct 3 '15 at 1:22
  • Sorry if you're not finding this helpful. I did read your entire question. To utilize any hook, you need to write an extension that calls that hook. The EE dev docs explain how to do that, and the FF docs tell you which hooks are available. You cannot just directly call a hook in a template. You can completely hijack what freeform does depending on what hook you decide to use, including skipping the insert into the freeform table. So to recap, to use a hook, you need to have an extension that has that hook registered and a method to perform what ever you want after it is triggered. – Jim Wyse Oct 3 '15 at 1:44
  • Think of it this way, when freeform runs, when each hook in it is reached, it stops, checks the extension table to see if that hook is registered, if so, runs that extension and method, and returns back to freeform when its finished. But you don't want to finish the insert, so you can direct the extension somewhere else. – Jim Wyse Oct 3 '15 at 1:44
0

Here we go...

So you have your first form (taking first name, last name, and email address). It's a FreeForm form, displayed on the client side, with rendered template code you've shown. When a user fills in the data and submits, it sends a POST request to what is called and Action ID (ACTid), which is a sort of API portal between the client and the ExpressionEngine (custom)? module. Here's an example ACT address:

https://www.domains-rock.com/?ACT=666

When a module is properly installed, there is a DB table (generally called exp_action) that gets inserted rows that create an association between an ACTion ID and a module's class method. For FreeForm, it would have a table row that associated ACTion ID 666 with the method that handles the form submission. That method then has a code hook in it. The engine looks at that hook and looks at the exp_extensions table to see if any installed extensions want to run their own class's methods inside of the code in the FreeForm submission method.

> i submit form
> FeeForm EE addon receives it
> starts processing it, but starts off with the insert_begin hook
>  - your extension hooks to that, so it takes over code control here
>  -  -  you get passed form info, whatever, into your extension method
>  -  -  you modify it and return it, or return false if invalid, whatever
>  - your extension ends, return form submission control to FreeForm
> FreeForm finishes up with the submission process.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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