5

I'm using (the latest) Freeform Pro to create forms with its Composer feature. Then I'm using the Freeform Channel Fieldtype to assign a form to a specific channel entry. In my template, I'm outputting the form by simply calling the channel field name. Something like this:

{exp:channel:entries
    channel="forms"
    url_title="{segment_2}"
    dynamic="no"
    limit="1"
    disable="member_data|categories|pagination"
}
    <div class="form-header">
        <h2>{title}</h2>
        {form_description}
    </div>
    {form_form}
    {if no_results}{redirect="404"}{/if}
{/exp:channel:entries}

...where {form_form} is the Freeform Channel Field. This will output the channel entry and form as expected.

In the Freeform Channel Field, you can also define the Return path for the form. However, the only dynamic segment you can set is the Entry ID of the Freeform entry: form/sent/%%entry_id%%

I need to add the URL title of the associated channel entry in this return path, so something like: form/sent/{url_title}/%%entry_id%% — is this possible?

On top of that, I'd like all my forms to have this particular return path, so there's no need for that input field in the channel form. Can you set the default value and hide the input field?

2 Answers 2

3

I'd suggest doing this via an extension - your best bet is likely to use the freeform_module_insert_end hook, with one extra form input.

So in your form, add a hidden input so the extension knows the url_title:

<input type="hidden" name="channel_entry_url_title" value="{url_title}" />

This is untested, but it should work:

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'] = 'form/sent/'.ee()->input->post('channel_entry_url_title').'/'.$entry_id;
    }
}

(Since $obj is an object, it's passed by reference, and params is a public variable, so it should set no problem.)

2
  • Modifying $obj->params['return'] is a workable workaround for now. I couldn't use a hidden input field with the {form_form} syntax (the {url_title} remained unparsed in the composer template) so I had to do a string replace on the referrer instead. As for part 2 of my Q (hiding the return page field), that doesn't seem possible. A small hack did help, tho.
    – Low
    Jun 13, 2014 at 13:28
  • Looking to create an extension like this with the same functionality. Could you perhaps take a look at my extension code on this question, can't seem to find the issue expressionengine.stackexchange.com/questions/38117/…
    – Thomas K
    Sep 13, 2016 at 19:32
1

Failing any native way to do this, which I'm not sure if it exists or not, what I usually do is make a single return template with a {exp:freeform:entries} tag, pulling the entry ID from the URL.

Then I use a conditional inside the tag to perform a redirect based on one of the fields in the entry.

It's an extra redirect and you have to add a hidden field for whatever your condition is based on, so it's not the ideal solution, but it works.

Your Answer

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

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