The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Prefilling title on a contact page.
PaulPott
post Feb 7 2017, 05:03 PM
Post #1





Group: Members
Posts: 3
Joined: 7-February 17
Member No.: 26,302



Hi guys was wondering if anyone could help me out, I have been googling for hours for a solution but to no avail sad.gif .

Basically I want to know how I can create a contact me link on a page that will take the user to the main contact me page of my website but fill out the title part of the form with a description of the previous page.

Any help would be greatly appreciated smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 7 2017, 05:30 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Where should this description come from? The TITLE of the page?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 7 2017, 06:04 PM
Post #3


.
********

Group: WDG Moderators
Posts: 9,653
Joined: 10-August 06
Member No.: 7



The link URL to the contact page might contain a query string that reveals the previous page. For example, on the page "foo.html" the link URL to the contact page might be "contact.html?from=foo". Then a script on the contact page might select the description related to foo from an array of descriptions.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
PaulPott
post Feb 7 2017, 06:27 PM
Post #4





Group: Members
Posts: 3
Joined: 7-February 17
Member No.: 26,302



The site is a very simple image gallery, there isn't ever going to be hundreds of images so I elected to go with a simple layout from the gallery page displaying a grid of thumbnail pictures, once one is clicked it opens up to a new page specifically about that image alone. The contact page contains no images, I don't want people having to flick back and forth between the contact form and the previous picture, I would prefare when the contact link is clicked that the info about the picture would automatically fill the title of the contact form.


Gallery.html > select thumbnail > open Image1.html > select enquire about image > Contact.html with title pre filled with name of picture.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 7 2017, 06:38 PM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



I was wondering WHERE that info is to start with, if it exists. You could hard code a query string per Christians directives, but if the info needed, or at least part of it, is already available on the page there may be ways to extract it so you don't need to hard code the query string.

Do you for example have <title>Name of the picture</title> you could extract the text content of TITLE with JavaSript and put it into the query string. On the contact page another script would get the name of the image out of the query sting and use it in the form. That way you can use the same script on all image pages and don't need to edit anything for each new page.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
PaulPott
post Feb 7 2017, 07:02 PM
Post #6





Group: Members
Posts: 3
Joined: 7-February 17
Member No.: 26,302



QUOTE(pandy @ Feb 7 2017, 06:38 PM) *

I was wondering WHERE that info is to start with, if it exists. You could hard code a query string per Christians directives, but if the info needed, or at least part of it, is already available on the page there may be ways to extract it so you don't need to hard code the query string.

Do you for example have <title>Name of the picture</title> you could extract the text content of TITLE with JavaSript and put it into the query string. On the contact page another script would get the name of the image out of the query sting and use it in the form. That way you can use the same script on all image pages and don't need to edit anything for each new page.


That sounds like a good solution, what sort of scripts would I need to be running to pull that off?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 7 2017, 07:30 PM
Post #7


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



The first part could go something like this. Note that you must have a TITLE if you try it. You needn't use TITLE for this, but that's how the example is written.

CODE

function qString()
{
   var imgname = document.getElementsByTagName("title")[0].textContent;
   var contactURL = 'http://htmlhelp.com?img=' + imgname;
   window.location = contactURL;
}


HTML
<a href="http://htmlhelp.com" onclick="qString(); return false">Contact</a>


Exchange http://htmlhelp.com for the real URL of course. Note that you should have the URL in the href of the link so it will work for those without JS. On the contact page you need a script that grabs the image name from the query string and does what it is you want done with it.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Feb 7 2017, 11:25 PM
Post #8


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



@pandy, I took your code and rewrote it a little. This line:
CODE
var imgname = document.getElementsByTagName("title")[0].textContent;
Becomes:
CODE
var imgname = document.title;

While this line:
CODE
var contactURL = 'http://htmlhelp.com?img=' + imgname;
Becomes:
CODE
var contactURL = 'http://htmlhelp.com?img="' + imgname + '"';
The parameter should be quoted, in case it contains spaces.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 04:28 AM