Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Update page title

New Here ,
Mar 02, 2012 Mar 02, 2012

Hi,

I create a form that allows user to change the HTML page title. It works, but after the form is submitted with the new page title, the title does not change immediately. The user has to refresh the page or go to another page to see the changed title. Is there a way to completely refresh the page on form submit and immediately show the results (ie new title) to the user?

1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 02, 2012 Mar 02, 2012

Regarding:

I cannot post my exact case example, as it is pulling data from the database...

Maybe the reason for this to work is that I put the form ABOVE the header...

The position of the form is irrelevent.  All that matters is that you set the variable before you attempt to use it.

To move forward, I suggest starting with the page that works, and start adding bits from the page that doesn't work until you have completely re-assembled it.  And remember, test early, test often, and test again.    

Translate
Community Expert ,
Mar 02, 2012 Mar 02, 2012

Could be that what you call the "new page" isn't the new page at all. The browser may be displaying a cached copy of the old page. It might help for you to add not just the title, but the following headers as well:

<cfheader name="Cache-Control" value="no-cache,no-store,must-revalidate">

<cfheader name="Pragma" value="no-cache">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2012 Mar 02, 2012

Thanks. However, it doesn't seem to work. The title still does not refresh after the form with settings is submitted, but all the other settings like website footer do update with new values immediately.

Here is my current header:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<cfheader name="Cache-Control" value="no-cache,no-store,must-revalidate">

<cfheader name="Pragma" value="no-cache">

<head>

          <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

          <link rel="stylesheet" type="text/css" href="/styles/stylesheet.css"/>

          <title>

                    <cfoutput>#qSettings.websiteTitle#</cfoutput>

          </title>

</head>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 02, 2012 Mar 02, 2012

I take it you are actually setting qSettings.websiteTitle *before* that code snippet there?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2012 Mar 02, 2012

Of course, that is just part of the header file. As I said, the whole logic works and title gets updated, but not immediately as everything else on the page that is beind modified through form field like footer or custom texts.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 02, 2012 Mar 02, 2012

In which case take a copy of your entire page and cut it down to a minimal working example, then post your code on here so one of us can test it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2012 Mar 02, 2012

I created this example and, suprisingly it works:

<cfform>

          <cfinput type="text" name="websiteTitle">

          <cfinput type="submit" name="submit">

</cfform>

<cfif isDefined("form.submit")>

          <cfset websiteTitle = form.websiteTitle>

<cfelse>

          <cfset websiteTitle = "no_title">

</cfif>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

          <cfheader name="Cache-Control" value="no-cache,no-store,must-revalidate">

          <cfheader name="Pragma" value="no-cache">

          <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

          <link rel="stylesheet" type="text/css" href="/styles/stylesheet.css"/>

          <title>

                    <cfoutput>#websiteTitle#</cfoutput>

          </title>

</head>

<body>

</body>

I cannot post my exact case example, as it is pulling data from the database...

Maybe the reason for this to work is that I put the form ABOVE the header...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2012 Mar 02, 2012

Eleeist wrote:

Maybe the reason for this to work is that I put the form ABOVE the header...

Put the form in the body, where it has to be anyway, and tell us what happens.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2012 Mar 02, 2012

It works ie the title refreshes with new value when I hit the submit button.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2012 Mar 02, 2012

Quick feedback. From my initial tests it appears to be unrelated to cache or to the position of the form.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2012 Mar 02, 2012

Regarding:

I cannot post my exact case example, as it is pulling data from the database...

Maybe the reason for this to work is that I put the form ABOVE the header...

The position of the form is irrelevent.  All that matters is that you set the variable before you attempt to use it.

To move forward, I suggest starting with the page that works, and start adding bits from the page that doesn't work until you have completely re-assembled it.  And remember, test early, test often, and test again.    

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2012 Mar 02, 2012

I have finally got to the root of the problem - the sequence in which code is executed.

I have fixed this and now everything works just fine. Thanks everyone for help .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2012 Mar 02, 2012

Eleeist wrote:

I have finally got to the root of the problem - the sequence in which code is executed.

I have fixed this and now everything works just fine. Thanks everyone for help .

Great. I'll just append what I ended up with, just in case it contains something you might want to use.

<cfif isDefined("form.submit")>

          <cfset websiteTitle = form.websiteTitle>

<cfelse>

          <cfset websiteTitle = "no_title">

</cfif>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

          <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

          <link rel="stylesheet" type="text/css" href="/styles/stylesheet.css"/>

          <title>

                    <cfoutput>#websiteTitle#</cfoutput>

          </title>

</head>

<body>

<cfform>

          <cfinput type="text" name="websiteTitle" required="yes" message="Supply the title">

          <cfinput type="submit" name="submit">

</cfform>

</body>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 02, 2012 Mar 02, 2012
LATEST

Often the simplest explanation is the one to try first

As an improvement to your code, you can replace the five-line if-statement with a one-liner:

<cfparam name="form.websiteTitle" default="no_title" />

That'll achieve the same thing.

O.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources