Capture URL of form submission page

I have a hard coded form so not one generate directly within Freeway. I am using the same form throughout my site and wanted to add a piece of code that would capture the url of the page the form is submitted from.

I have taken a look online to see, but cannot isolate a particular piece of code that I could use.

Does anyone know of a simple piece of code I can add in to my form code to accomplish this?

Thanks


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Nathan,
Is the form on a page that uses PHP already? If so I’d be inclined to have PHP echo the current page URL into a hidden input on the form. This will get set when the page is served and submitted to the form processor when the form is submitted.
If you don’t have PHP running on the page and would rather not change the file extension for SEO or discoverability reasons (although there are ways around these) then you can do the same sort of thing by using JavaScript to populate the hidden field when the page loads. This is less bullet-proof as it relies on the browser to do the work rather than the server but can also get the job done quite easily.

http://www.freewayactions.com/test/hidden-url-form.php

Here’s an example page where if you view source on the page you can see the PHP has populated the first hidden field. You’ll see JavaScript has done the same to the second if you use the Web Inspector. The original HTML, PHP and JS source code is linked so you should be able to see what is going on.
Regards,
Tim.

On 9 Dec 2013, at 10:44, BigG wrote:

I have a hard coded form so not one generate directly within Freeway. I am using the same form throughout my site and wanted to add a piece of code that would capture the url of the page the form is submitted from.

I have taken a look online to see, but cannot isolate a particular piece of code that I could use.

Does anyone know of a simple piece of code I can add in to my form code to accomplish this?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Yes the page does use php already so that’s good.

This looks perfect Tim - I will give it a whirl and feedback - much appreciated mate.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

This is the code I have inherited that probably needs a little refining:

Where would I place the PHP code?

<perch:form id=“Call-Back” method=“post” app=“perch_forms” role=“form” >

<div id="submit_box2">
   <perch:input type="submit" name="submit" id="submit" value="Let's Go"/>
</div>

<perch:success>
	<script type="text/javascript">
		window.location = 'http://www.newyoubootcamp.com/success.php';
	</script>
</perch:success>

</perch:form>


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Nathan,
I’ve yet to wok with Perch forms but I would imagine that you can add the hidden field in anywhere in the form as it doesn’t get rendered in the browser.

Try this;

<perch:form id="Call-Back" method="post" app="perch_forms" role="form" >
<div class="blockheadings" style="float:left; width:412px; margin-bottom:20px;">
	<perch:content id="heading" type="text" label="Heading" required="true" />
</div>
<div style="float:left; width:412px;">
	<perch:content id="text" type="textarea" label="Text" html="true" editor="ckeditor" />
</div>
	<div class="input" style="margin-bottom:5px;">
		<perch:input id="name2" type="text" value="Name" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" required="true" size="50"/>
	</div>
	<div class="input" style="margin-bottom:5px;">
		<perch:input id="email2" type="text" value="Email" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" required="true" size="50" />
	</div>
	<div class="input" style="margin-bottom:5px;">
		<perch:input id="telephone2" type="text" value="Telephone" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" required="true" size="50" />
	</div>
	<div class="input" style="margin-bottom:10px;">
		<perch:input id="date2" type="text" value="When do you want to go?" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" required="true" size="50" />
		<perch:input type="hidden" name="the_url" value="<?php echo 'http://',$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>"/>
	</div>
	<div class="humans" style="margin-bottom:0px;">
		<perch:input type="text" id="extras" antispam="honeypot"/>
	</div>
		
	<div id="submit_box2">
	   <perch:input type="submit" name="submit" id="submit" value="Let's Go"/>
	</div>
	
	<perch:success>
		<script type="text/javascript">
			window.location = 'http://www.newyoubootcamp.com/success.php';
		</script>
	</perch:success>
</perch:form>

Regards,
Tim.

On 9 Dec 2013, at 12:41, BigG wrote:

Where would I place the PHP code?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Tim

I get this showing after the last field

"/>

Nathan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Try leaving the perch: part off of the input definition. Make it just a normal input with a PHP echo inside the value attribute:

<input type="hidden" name="the_url"
value="<?php echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>" />

That should work. My guess here is that Perch is double-decoding your code.

Walter

On Dec 9, 2013, at 10:10 AM, BigG wrote:

Thanks Tim

I get this showing after the last field

"/>

Nathan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I’m not too sure why Perch needs the inputs to be perch-prefixed but I suspect it does something on the admin end to allow you to control the form or the data collected.
I’ll make a note to look into this when I have a second.
Regards,
Tim.

On 9 Dec 2013, at 15:44, Walter Lee Davis wrote:

Try leaving the perch: part off of the input definition. Make it just a normal input with a PHP echo inside the value attribute:

That should work. My guess here is that Perch is double-decoding your code.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That’s correct. There’s a fair bit of optional built-in processing that can be done by Perch if necessary: store submissions in the db or tie it into a MailChimp account etc.

Todd

I’m not too sure why Perch needs the inputs to be perch-prefixed but I suspect it does something on the admin end to allow you to control the form or the data collected.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I remove the perch prefix and left it as a standard input, but the URL of the page is not showing up in the reply.

I will ask Perch to see if they know why.

Thanks


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Perch replied by saying:

It would need to be perch:input, and you’d need to pass the value in using PerchSystem::set_var().


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options