How to echo current page location in the form
Posted: 18 June 2008 12:08 PM   [ Ignore ]
Newbie
Rank
Total Posts:  7
Joined  2005-10-28

I have a form that appears on most every page of the site. I’d like to create a hidden input that basically echoes the current page url when form is submitted. How would I do that? What tags? EE tags? or any freeform tags?

Profile
 
 
Posted: 18 June 2008 01:35 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2320
Joined  2006-10-18

I do this with the {segment_#} variable and some conditionals: smile

return="{segment_1}{if segment_2}/{segment_2}{/if}{if segment_3}/{segment_3}{/if}"

 Signature 
Profile
 
 
Posted: 19 June 2008 02:04 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  7
Joined  2005-10-28

Thanks, Pie Man. I suspected it was segments (Have been walking the URL segments path in my latest EE learning curves. They’re sweet, but still a bit new). Thanks for the IF examples. oh boy, I’ve been learning more about them recently).

Here’s what I ended up doing (I put a line break in the code so as not to break the page:

<input type="hidden" name="currentpage" id="currentpage"
value="{homepage}/{segment_1}/{if segment_2}{segment_2}/{/if}{if segment_3}{segment_3}/{/if}" />

I then created a freeform field called currentpage. (so I can call that in the template when I send the email notification)

Your comment put the code as part of return=. At the moment, my form returns the visitor to the same (self) page. Is it possible to skip the above step I did and simply call the return value in the email notification template instead?

Also, speaking of return=, I’m intrigued with the ideas contained in this thread for returning an extra segment for thank you and then parsing that to add another statement to the form to tell the person, thanks, we got your info. (a tacked on “/thanks” a end of the URL wouldn’t be a problem for email notification)

Profile
 
 
Posted: 19 June 2008 02:39 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2320
Joined  2006-10-18
AuntiAlias - 19 June 2008 02:04 PM

Thanks, Pie Man. I suspected it was segments (Have been walking the URL segments path in my latest EE learning curves. They’re sweet, but still a bit new). Thanks for the IF examples. oh boy, I’ve been learning more about them recently).

Awesome aren’t they? LOL

AuntiAlias - 19 June 2008 02:04 PM

Your comment put the code as part of return=. At the moment, my form returns the visitor to the same (self) page. Is it possible to skip the above step I did and simply call the return value in the email notification template instead?

Are you talking about displaying the Freeform Email Notification template that’s supposed to be emailed?
Unfortunately not available, unless you’re referring to doing something like what I have below… smile

AuntiAlias - 19 June 2008 02:04 PM

Also, speaking of return=, I’m intrigued with the ideas contained in this thread for returning an extra segment for thank you and then parsing that to add another statement to the form to tell the person, thanks, we got your info. (a tacked on “/thanks” a end of the URL wouldn’t be a problem for email notification)

Nice eh? Eliminates a template rasberry
I do this all the time now… in case you’re asking on how to do it… this is how:

1. Obviously, add an extra segment to the return="” parameter… lets say ”thanks
2. Set up a conditional on that same template (or any template you wish) that detects the - in this case - 3rd segment in the URL:

{if segment_3 == "thanks"}Thank you{if logged_in} {screen_name}{/if}! Your question has been submitted.{/if}

smile

 Signature 
Profile
 
 
Posted: 19 June 2008 05:04 PM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  7
Joined  2005-10-28

The parameter thanks is placed at the end of the

thanks for that example (your #2) I’m going to have to do a bizillion conditionals for it, though, because the form (in sidebar) falls on segment_1, segment_2, and segment_3 pages. Fun challenge! smile

Later. That was easier than I thought, actually:

{if segment_2 == "thanks"}{embed="embeds/sidebar-form-thanks"}{/if}
{if segment_3
== "thanks"}{embed="embeds/sidebar-form-thanks"}{/if}
{if segment_4
== "thanks"}{embed="embeds/sidebar-form-thanks"}{/if}

(am using embeds because I’m using Michael Boyink’s most excellent Miscellaneous Content weblog trick to make that part editable)

Profile
 
 
Posted: 20 June 2008 12:26 PM   [ Ignore ]   [ # 5 ]
Newbie
Rank
Total Posts:  7
Joined  2005-10-28

Lovely. simplified the previous code some by doing :

{if segment_2 == "thanks" OR segment_3 == "thanks" OR segment_4 == "thanks"}

and it worked fine.

That way I could put the body of the form in an {else:if} statement and so show either the form or the thank you message.

However. I was trying something else… to add an in-page link www.somedomain.com/index.php/company/testimonials/thanks#ty
The a name="ty” at the Thank You statement will scroll browser down to where the form used to be, making it obvious that yes, we got their input, thanks.

But it seems that freeform’s return= will automatically append a final / at the end of the url. Is there any way to override it?

The code I’m using in the form (broken into 3 lines for ease of reading. Look at the third line):

{exp:freeform:form form_name="site_lead" required="name|email|phone1"
notify="blah@domain.com" template="contact_form" charset="utf-8"
return="{segment_1}/{if segment_2}{segment_2}/{/if}{if segment_3}{segment_3}/{/if}thanks#ty"}

Which results in this (note the / at final end of URL:
www.somedomain.com/index.php/company/testimonials/thanks#ty/

If there’s a final slash in the URL, no scroll down.
If there’s NO final slash, then page WILL scroll.

I guess I can put the thank you message higher in sidebar to omit scrolling (but that means more embed templates). Workarounds? We always have workarounds. smile

Profile
 
 
Posted: 20 June 2008 12:32 PM   [ Ignore ]   [ # 6 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2320
Joined  2006-10-18

Haha.... damn Freeform!  shut eye  rasberry LOL

Let me dig around in the code rasberry

 Signature 
Profile
 
 
Posted: 20 June 2008 12:42 PM   [ Ignore ]   [ # 7 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2320
Joined  2006-10-18

AuntiAlias,

Which versions of ExpressionEngine and Freeform are you running? smile

I’m using latest of both and it’s stripping the #ty from my return path.

 Signature 
Profile
 
 
Posted: 20 June 2008 02:17 PM   [ Ignore ]   [ # 8 ]
Newbie
Rank
Total Posts:  7
Joined  2005-10-28

ExpressionEngine 1.6.3 - © Copyright 2003 - 2008 - EllisLab, Inc.
Script executed in 0.6227 seconds 17 SQL queries used
Build:  20080421

Freeform Open-ended form engine 2.6.5 Installed Remove

Let me try this thing one last time. I did lots of form template changes.

Nope: this is how it returned the final part /thanks#ty/.

Just for grins, I include my entire template [embeds/sidebar_responseform] here, altered only in that I changed my email address. Also broke up the exp:freeform:form opening tag to 3 lines so as not to break this page.

This form appears in the bottom of the sidebar of most of the pages of the site… hence all the segment_2 segment_3 and segment_4 froo-frah:

{if segment_2 == "thanks" OR  segment_3 == "thanks" OR segment_4 == "thanks"}{embed="embeds/sidebar-form-thanks"}
{if
:else}
{exp
:freeform:form form_name="site_lead" required="name|email|phone1"
notify="name@domain.com" template="contact_form" charset="utf-8"
return="{segment_1}/{if segment_2}{segment_2}/{/if}{if segment_3}{segment_3}/{/if}thanks#ty"}



{embed
="embeds/sidebar-form-top"}

<input type="hidden" name="currentpage" id="currentpage"
value="{homepage}/{segment_1}/{if segment_2}{segment_2}/{/if}{if segment_3}{segment_3}/{/if}" />

<
label for="name">Name</label>
<
input type="text" name="name" id="name" />

<
label for="email">Email</label>
<
input type="text" name="email" id="email" />

<
label for="phone1">Phone (with area code)</label>
<
input type="text" name="phone1" id="phone1" />

{embed="embeds/sidebar-form-bottom"}
<input name="Submit" type="submit" value="submit" />


{/exp:freeform:form}
{
/if}

I’ve been caught out elsewhere while building this site when I’ve used exp:weblog:entries and not had dynamic="off" ... I don’t know if that would affect outcome here.

Profile
 
 
Posted: 23 June 2008 08:22 AM   [ Ignore ]   [ # 9 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2320
Joined  2006-10-18

Hmmmm… I’m not sure how to get around this…

Try this:

return="{path=/}{segment_1}/{if segment_2}{segment_2}/{/if}{if segment_3}{segment_3}/{/if}thanks/#ty"

 Signature 
Profile