Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer
    
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 at 13:28

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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