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.

Show Segment In Free Form

October 17, 2008 12:32pm

Subscribe [2]
  • #1 / Oct 17, 2008 12:32pm

    Jay Logan

    140 posts

    Just can’t get it to work. The catch is, the form is in an entry and I use allow_ee to show form in template. I want the form to report what URL it has been submitted from. Any suggestions?

  • #2 / Oct 17, 2008 12:43pm

    bkuberek

    124 posts

    create a hidden field in the form and populate the value with the URI.

    <input type="hidden" name="page_uri" value="{segment_1}/{segment_2}/{segment_3}" />

    don’t use the name URI as it is already used by the system. Let me know if it doesn’t work.

    EDIT:

    I speculate that if you create a freeform field called URI, it will automatically be populated since the form has a URI hidden input. I will try that.

  • #3 / Oct 17, 2008 1:18pm

    Jay Logan

    140 posts

    Hi, I tried the URI field and it just posts as blank. And I tried the hidden line and is doesn’t parse {segment_1}, {segment_2}, etc. Maybe because I have the form within the entry. Any way to get the URI to send with the notification e-mail. I still want to get the segment tag to work thought because for the return URI needs to be based on the URI. IE: http://www.site.com/product1/thank_you_page/

  • #4 / Oct 17, 2008 1:26pm

    bkuberek

    124 posts

    May I ask why you have the form in an entry? I may be able to help you with an alternative if I understand the overall goal.

  • #5 / Oct 17, 2008 1:50pm

    Jay Logan

    140 posts

    Well the site is for a company with several locations. Each location has it’s own “site” under the domain. Something like http://www.site.com/store1 and www.site.com/store2. So I’ve managed to make each location dynamically populate the different pages with the correct info using 1 template. That was a challenge by itself because I’m not using the Pages module to get links like http://www.site.com/store3/products/product1 etc. Everything is currently controlled with a series of weblogs. The each page is a different entry in the weblog. The page containing the form is an entry and the form works but I need it to dynamically populate a hidden field to let me know what store location the form was submitted from. I also need to send the user to a return page relative to the location site. I probably want to CC the store manager so I need to look into the store weblog and get that info.

    The page already looks into the stores weblog to show other information such as phone numbers and whatnot. I do stuff like {exp:weblog:entries weblog="locations"}{phone_number}{/exp:weblog:entries}

    Hmm….wonder if I could just open the weblog at the beginning of the entry, then use the url_title tag in the freeform tag. Will try when I get back from lunch. I’ll let you know.

  • #6 / Oct 17, 2008 2:40pm

    Jay Logan

    140 posts

    Got it working. Thanks!

  • #7 / Oct 17, 2008 3:16pm

    bkuberek

    124 posts

    Hmm….wonder if I could just open the weblog at the beginning of the entry, then use the url_title tag in the freeform tag.

    You can use {exp:weblog:entries ...} as many times you want on a page. I do the same thing.

    I wrap my HTML-header include with it so I can pass the page title to it. something like this:

    {assign_variable:css='<link rel="stylesheet" type="text/css" media="all" href="/css/css.css" />'}
    {exp:weblog:entries weblog="rsvp" show_future_entries="yes" show_expired="yes" limit="1"}
    {embed="includes/header" title_tag="{title} - RSVP - {site_name}" extra_css='{css}'}
    {/exp:weblog:entries}
    
    ...

    Just make sure you have limit=1 otherwise you get it many times.

    Regarding the form,

    if all stores have similar fields, you could have the form in a template, then the page will embed the form and pass the {url_title} to it. Then you can use PHP and whatever you need with those forms.

    If all stores have a different form, you could still have the form on a separate template. Then you add a Custom Field in the weblog entry called “Form Fields”. Then enter content in it like this:

    text:visitor_name:Your Name
    text:visitor_phone:Your Phone
    text:visitor_address:Your Address
    textarea:description:Enter a Description

    then in the form template use PHP to explode the line breaks, then again explode the (:) so you get an array of form field arrays.

    <?php
    /* PHP parse = input */ 
    
    global $FNS, $TMPL;
    
    $form_fields_raw = explode("\n", $TMPL->embed_vars['embed:form_fields']);
    
    $form_fields = array();
    
    foreach ($form_fields_raw as $raw)
    {
        $form_fields[] = explode(":", $raw);
    }
    ?>
    {exp:freeform:form form_name="STORE_<?=$TMPL->embed_vars['embed:url_title']?>"}
        <input type="hidden" name="page_uri" value="<?=$FNS->fetch_current_uri()?>" >
        
        <? foreach($form_fields as $field): ?>
        
        <? if ($field[0] == 'text'): ?>
    
        <label><?=$field[2]?></label>
    
        <input type="text" name="<?=$field[1]?>" value="" size="40" />
    
        <? elseif ($field[0] == 'textarea'): ?>
    
        <label><?=$field[2]?></label>
    
        <textarea name="<?=$field[1]?>" cols="60" rows="8"></textarea>
    
        <? endif; ?>
        
        <? endforeach; ?>
    
    {/exp:freeform:form}
  • #8 / Oct 18, 2008 11:47am

    Jay Logan

    140 posts

    Good stuff to know. I’m bookmarking this page for future reference. But I got the forms acting right now with something like this in the webblog entry.

    {exp:weblog:entries weblog="stores"}
    <h1>Contact Form</h1>
    
    Contact <em>{contact_name}</em> at {company_name} today for your next purchase.
    <b>Call Now: {contact_phone}</b>
    
    {exp:freeform:form form_name="contact_us" return="{url_title}/form_submitted/" template="contact_us" required="nameFirst|nameLast|email|zip|phoneDay"}
    <input type="hidden" name="store" value="{company_name}" />
        <fieldset>
            <legend>Contact Us</legend>
                
                <label for="nameFirst">First Name</label>
    
                <input name="nameFirst" id="nameFirst" type="text" size="25" class="" value="" maxlength="">
                
    
                
                <label for="nameLast">Last Name</label>
    
                <input name="nameLast" id="nameLast" type="text" size="25" class="" value="" maxlength="">
                
                
                
                <label for="email">E-Mail Address</label>
                <input name="email" id="email" type="text" size="25" class="" value="" maxlength="">
                
            
            
            <label for="street">Street Address</label>
    
            <input name="street" id="street" type="text" size="25" class="" value="" maxlength="">
            
            
            
            <label for="city">City</label>
            <input name="city" id="city" type="text" size="25" class="" value="" maxlength="">
            
            
            
            <label for="state">State</label>
    
            <input name="state" id="state" type="text" size="25" class="" value="" maxlength="">
            
            
            
            <label for="zip">Zip*</label>
            <input name="zip" id="zip" type="text" size="25" class="" value="" maxlength="">
            
            
            
            <label for="phoneDay">Phone</label>
    
            <input name="phoneDay" id="phoneDay" type="text" size="25" class="" value="" maxlength="">
            
    
        </fieldset>
    
        Please click "Submit" below & someone from our office will contact you shortly.
    
        
        <input name="submitForm" type="submit" value="Submit" class="button">
         
    {/exp:freeform:form}
    {/exp:weblog:entries}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases