ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Passing a parameter to a form?

November 04, 2010 6:16pm

Subscribe [2]
  • #1 / Nov 04, 2010 6:16pm

    soopafly

    5 posts

    Hello,
    I’m developing a site for a training center and have run into a wall. 

    Each class has about three dates that a user can inquire about by clicking on a “Learn more” button, which will take them to a form where they can fill out.  What I want is a single form with a “subject line” that will change depending on where they clicked in from.  So for example, if the user clicks on button for the December 5th class, s/he would be taken to a form with one of the fields pre-populated with something that read “I am inquiring about the December 5th class”

    I’m planning on using FreeForm if that matters. 

    Any help would be great! Thanks!

  • #2 / Nov 04, 2010 11:44pm

    the3mus1can

    426 posts

    In the link to the form page pass the url title for the class entry that they are inquiring about. ex. http://example.com/class/class-url-title


    {cf_class_subject} = field that stores that classes subject

    {exp:channel:entries 
        channel="classes-channel" 
        url_title="{segment_2}" 
        limit="1" 
        disable="categories|member_data|pagination|trackbacks"
    }
    
        {exp:freeform:form
           collection="a-collection"
           required="name|email"
           return="some/template"
           recipients="yes"
           recipient_limit="1"
           recipient_template="a-template"
        }
    
            <input type="text" name="subject" value="{cf_class_subject}" id="subject" />
            
            ....the rest of the form fields….
            
        {/exp:freeform:form}
    
    
    {/exp:channel:entries}
  • #3 / Nov 12, 2010 1:42am

    soopafly

    5 posts

    Thanks for the reply!!  I’ve tried exactly what you wrote and cannot get it to work.  I cannot get the class title passed on to the form.  Here are the parts of interest in my code:

    This is the link TO the form FROM the class page

    {exp:weblog:entries weblog="class-detail" disable="member_data|pagination|trackbacks" limit="1" url_title="{segment_2}"}
    <div class="reserve">
        <span>{location}</span>
        <a href="http://{site_url}training-classes/request-more-information/">Reserve class</a>
    </div><!-- #reserve -->
    {/exp:weblog:entries}

    “Reserve class” is the link to the form.


    And here is the form page:

    {exp:freeform:form
            required="phone|company|email"
            collection="Class Info Request"
            return="/contact-us/thank-you"
            form:class="contact-us" 
            notify="[email protected]"
            send_user_email="yes"
            template="contact-class"
            user_email_template="contact-class-user"
        }
        <label for="name">Inquiring About</label>
        <input type="text" name="subject" value="{cf_class_subject}" id="subject" />

    I guess I’m just confused on where {cf_class_subject} is pulling from

  • #4 / Nov 12, 2010 8:53am

    the3mus1can

    426 posts

    On the class details page you will need to pass the url_title for the class in the url that links to the form page.  Note that segment_3 contains the url_title.

    {exp:weblog:entries weblog="class-detail" disable="member_data|pagination|trackbacks" limit="1" url_title="{segment_2}"}
    <div class="reserve">
        <span>{location}</span>
        <a href="http://{site_url}training-classes/request-more-information/{url_tilte}/">Reserve class</a>
    </div><!-- #reserve -->
    {/exp:weblog:entries}

    On the form page you will need to get the url_title out of the url and use it to look up that class’s entry. Note we are passing segment_3 to the weblog entries loop in the url_title parameter.

    {exp:weblog:entries weblog="class-detail" disable="member_data|pagination|trackbacks" limit="1" url_title="{segment_3}"}
    {exp:freeform:form
            required="phone|company|email"
            collection="Class Info Request"
            return="/contact-us/thank-you"
            form:class="contact-us" 
            notify="[email protected]"
            send_user_email="yes"
            template="contact-class"
            user_email_template="contact-class-user"
        }
        <label for="name">Inquiring About</label>
        <input type="text" name="subject" value="{cf_class_subject}" id="subject" /> 
    {/exp:freeform:form}
    {/exp:weblog:entries}

    The form needs to be wrapped in a weblog entries loop.  The {cf_class_subject} represents the field in your weblog entry that holds the value of the class subject.  I did not know the structure of the your weblog fields so I had to make up a field name.  So substitute the tag for the field that holds the class subject in the entry whatever it is called.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases