Skip to main content
Inspiring
March 21, 2013
Answered

logging into an edit page

  • March 21, 2013
  • 1 reply
  • 3448 views

Hi everyone,

       I have set up a blog page on our site. I created an Add Blog page for engineers to enter the blog info. They choose who to send the info. in an email to have it approved. When the approver receives the email, there is a link they can click on to edit that blog info. When they click update, it approves the blog entry just entered and displays it on the Blog page. I also set up a login page that the engineers and approvers must log into before they can get to the add blog page or edit blog page. I have this working fine to get to the add blog page, but I'm having problems with the edit page. How can I get the link in the email to work correctly to get to the edit page, but having to login first? I've set this code on the add and edit pages:

<cfset MyHost = CGI.Server_Name>

<CFIF CGI.HTTP_Referer does not contain "#MyHost#">

<cflocation url="../Blog_Login/login.cfm" addtoken="No">

</CFIF>

    This code will not allow someone to just type in the direct link and use these pages. It re-directs them to a login page first. Is there a different way I should be using to get to the login page instead of this code? Once logged in, then they can go to these pages.So when the link in the email is clicked, it re-directs to the login page, but I can't get the login button to go to the  edit page because it has to go to a specific edit page with the correct BlogID so it updates the correct information just entered.I can get the link to work in the email just fine without going to the login page. Here's what I'm doing:

This is from the Add page after the engineer adds their info. and it gets emailed to the approver:

<cfloop query="ShowBlogInitials">

<cfif Users_Email is not "">

    <CFMAIL TO="#Users_Email#"

    FROM="andy@ironwoodelectronics.com"

        SUBJECT="Update Blog Entry">

       

<CFOUTPUT>

#Users_First_Name#,

An engineer has uploaded a new Blog entry. Please edit this and approve it. Follow this link:

http://www.ironwoodelectronics.com/blog/edit_blog.cfm?BlogID=#BlogID#

Thank you.

</cfoutput>

</CFMAIL>

</cfif>

</cfloop>

This is on the login page. I thought I would need to say that the BlogID needs to be defined in order to go to the validate page.

<cfinput type="button" name="submitBtn" onclick="applogin()" value="Approver Login">

<cfif isDefined("form.BlogID") and form.BlogID>

<input type="hidden" name="BlogID" value="#BlogID#">

</cfif>

This is on the validate page that directs the user to the correct page after they login. I kept the Add page in here to so you can see how that one works fine, but the Edit page doesn't. I could not get the relative path to work at all.

<cfif isDefined("form.eng_login") and form.eng_login>

<cflocation url="../blog/add_blog.cfm" addtoken="No">

<cfelseif isDefined("form.app_login") and form.app_login>

<cflocation url="http://www.ironwoodelectronics.com/blog/edit_blog.cfm?BlogID=#BlogID#" addtoken="No">

</cfif>

Then it should just go to the edit page to update the information.

<CFQUERY NAME="ShowBlog" DATASOURCE="#application.DataSource#">

SELECT  BlogID, Blog_Date, Blog_Info, Blog_Image, Blog_Approval_Initials, Approved_entry

FROM Blog

Where    BlogID=#url.BlogID#

</cfquery>

<CFQUERY NAME="ShowBlogInitials" Datasource="#application.DataSource#">

SELECT *

From Blog_Users

where Blog_Initials = 'true'

Order by Initials

</CFQUERY>

Then the items to edit are displayed.

I tried to not include all the code, so hopefully this is enough. If you would need all the pages to see this, I could email them to anyone that could help me. Thanks for your help in advance.

Andy

    This topic has been closed for replies.
    Correct answer jamie61880

    I added this: ?blogId=#URL.blogId# to the validate.cfm link in the javascript code on the login page that I mentioned above, and am able to get to the edit page and not have the BlogID undefined error, but I cannot get the query on the eidt page to work. I have this query on the edit page:

    <CFQUERY NAME="ShowBlog" DATASOURCE="#application.DataSource#">

    SELECT  BlogID, Blog_Date, Blog_Info, Blog_Image, Blog_Approval_Initials, Approved_entry

    FROM Blog

    Where    BlogID=#url.BlogID#

    </cfquery>

    The error says:

    Incorrect syntax near '='    on the edit_blog.cfm: line 13

    11 : From Blog

    12 :

    13 : Where BlogID=#url.BlogID#

    14 :

    15 : </cfquery>

    If I run that cfdump code on the edit page, it says the BlogID is an empty string. Does this mean the BlogID is not being passed from the Login page to the validate page to the edit page, and that's why this query is not working? This query is how I display the correct info. from that BlogID number.

    Andy


    Ashish,

            I figured out what my problem was. I did not have CFoutput tags around the javascript above on the login page. I am now able to get to the edit page after logging in and update the info. on the correct BlogID. Thank you very much for all your help! I really appreciate it!!!

    This is what's on my login page now with the javascript:

    <cfoutput>

    <script type="text/javascript">

    function englogin()

    {

    document.foo.eng_login.value="yes";

    document.foo.app_login.value="no"

    document.foo.action ="validate.cfm?BlogID=#URL.BlogID#";

    document.foo.submit();

    }

    function applogin()

    {

    document.foo.app_login.value="yes";

    document.foo.eng_login.value="no";

    document.foo.action ="validate.cfm?BlogID=#URL.BlogID#";

    document.foo.submit();

    }

    </script>

    </cfoutput>

    Andy

    1 reply

    Inspiring
    March 21, 2013

    Hi,

       In Appliaction.cfc we can add onrequest function like

     

      // Here i am keeping blogid in url after redirect also. similarly after validation you can keep bolg id with you for edit home page

      // Here /cftenproj/proj2/index.cfm is my home page

              <cffunction name="onRequestStart" returntype="boolean" >

                        <cfset blogid = isDefined("url.blogid")?url.blogid:0 />

                        <cfif CGI.SCRIPT_NAME neq '/cftenproj/proj2/index.cfm' &&

                                  (not isDefined("session.isLogedIn") || not session.isLogedIn)>

                                  <cflocation url="/cftenproj/proj2/index.cfm?blogId=#blogid#"  />

                        </cfif>

                        <cfreturn true>

              </cffunction>

    Inspiring
    March 21, 2013

    Ashish,

        I don't understand what any of this is. Does this .cfc file only work in version 9 of Cold Fusion? We are running 7 still I think. I tried adding your code to my Application.cfm page and changed the paths to be on our site, but I get an error. This is what I have on the Application.cfm page:

    <cfapplication name="IronwoodCatalog"

    clientmanagement="Yes"

    setclientcookies="Yes">

    <!--- Set Application Constants --->

    <!--- <CFIF NOT IsDefined("application.Initialized")> --->

    <CFSET application.DataSource="IronwoodCatalog">

    <CFSET application.Initialized="Yes">

    <cffunction name="onRequestStart" returntype="boolean" >

                        <cfset blogid = isDefined("url.blogid")?url.blogid:0 />

                        <cfif CGI.SCRIPT_NAME neq 'login.cfm' &&

                                  (not isDefined("session.isLogedIn") || not session.isLogedIn)>

                                  <cflocation url="edit_blog.cfm?BlogID=#BlogID#"  />

                        </cfif>

                        <cfreturn true>

    </cffunction>

        Am I doing something wrong? Does this only work on a .cfc page and not .cfm page? Even when I go through and fix all the errors, it still says that the BlogID is Undefined. What else can I try? Or do I have to change the code above a little?

    Andy

    Inspiring
    March 21, 2013

    Ashish,

          I changed the Application.cfm page to this:

    <cfapplication name="IronwoodCatalog"

    clientmanagement="Yes"

    setclientcookies="Yes">

    <!--- Set Application Constants --->

    <!--- <CFIF NOT IsDefined("application.Initialized")> --->

    <CFSET application.DataSource="IronwoodCatalog">

    <CFSET application.Initialized="Yes">

    <cfset blogid = isDefined("url.blogid") />

    I am getting closer. I am able to at least get to the edit page. The only problem I'm having is getting it to edit the correct information. The wrong row of info. is displayed. It just displays the first row and not the correct BlogID I want to update. Any ideas how I could make this work? Thanks.

    Andy