13 Replies Latest reply on Mar 25, 2013 2:33 PM by jamie61880

    logging into an edit page

    jamie61880 Level 1

      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

        • 1. Re: logging into an edit page
          Ashish Todon Level 1

          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>

          • 2. Re: logging into an edit page
            jamie61880 Level 1

            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

            • 3. Re: logging into an edit page
              jamie61880 Level 1

              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

              • 4. Re: logging into an edit page
                Ashish Todon Level 1

                Great!!!

                       Now i think we should pass blogId in URL. like  

                 

                Suppose you have this URL in mail

                     www.you_domainname.com/your_edit_page.cfm?blogId=34  // here this is correct blog id which we want to edit

                 

                Add this to your Application.cfm

                 

                                   <!--- Here i am retrieving blog id from url if no blogId is

                                           there in url then i set it to '0'(by this even we can add exception handling)--->

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

                 

                                    <!--- Some Notes:

                                            1) Here I am checking your session existes or not.

                                            2) IF sesssion does not exist, I am redirecting to login page by saving my blog id in url

                                                by doing Login.cfm?BlogID=#BlogID#

                                            3) And after valid login, I am redirecting to edit home page by saving my blog id in url

                                                by doing edit_home?BlogID=#BlogID#

                                            4) In edit home page you can drive blogId from URL and can bring proper data  ---> 

                 

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

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

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

                                    </cfif>

                 

                Sorry for my post #1 the code was for cf8,9,10. 

                • 5. Re: logging into an edit page
                  jamie61880 Level 1

                  Ashish,

                         I tried this on the Application page:

                   

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

                   

                     But I get this error:

                   

                  Invalid token '?' found on line 13 at column 40.

                   

                  But if I remove the ?, then I get this error:

                  Invalid CFML construct found on line 13 at column 40.

                  ColdFusion was looking at the following text:


                  url.blogid

                   

                  Then I have to remove the url.blogid and then the : and then the 0. Once this is all gone, then the login page loads. But then I'm back to where I started and it doesn't go to the correct BlogID to update. Does the If cgi.script code above go on the Applicaton page also? Where does the
                  Login.cfm?BlogID=#BlogID# and edit_home?BlogID=#BlogID#  go?

                   

                  Andy

                  • 6. Re: logging into an edit page
                    jamie61880 Level 1

                    Ashish,

                         I have the url in my email with the correct BlogID number. When I have this code on the Application page:

                    <cfset BlogID = isDefined("url.BlogID")>

                     

                        Why does my Login page not capture that BlogID number? If I try and just output the BlogID number on the login page, it just says, "NO". Why is this? What does this mean?

                     

                    Andy

                    • 7. Re: logging into an edit page
                      Ashish Todon Level 1

                      jamie61880 wrote:

                       

                          Why does my Login page not capture that BlogID number? If I try and just output the BlogID number on the login page, it just says, "NO". Why is this? What does this mean?

                             IsDefined("Your_variable") // This is for checking if this variable exist or not.it return ('yes' or 'no')

                       

                             <cfset blogid = isDefined("url.blogid")?url.blogid:0 />  // This is a conditional statement if url.blog is defined then

                                                                                                                              take blog id form URL else 0 will be assigned to blogid.

                       

                             The above statment can be written as or same as :-

                       

                              <cfif isDefined("url.blogid") />

                                   <cfset blogID = url.blogID />

                              <cfelse>

                                  <cfset blogID = 0 />                            

                              </cfif>

                      • 8. Re: logging into an edit page
                        jamie61880 Level 1

                        Ashish,

                             I put this code onto the Application page like this and I think the BlogID is still not getting defined. I tried to output the BlogID number on the login page and it just dispalys 0. Shouldn't this at least display the BlogID number from the email? Am I doing something wrong when I'm sending the link to the email? Here's how I have that set up:

                         

                        <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>

                         

                            I don't have a relative path for the link in the email because I couldn't get it to output a query correctly. But I see the BlogID number, such as 63 in the email link. I think it's getting lost when it gets re-directed to the Login page. So then when I log in, there's no BlogID number. It just chooses the first row in the database. I had to comment this out:

                        Where BlogID=#url.BlogID#

                        in the query on the Edit page in order for it to display something. If I keep it in there, I don't get any info. to display on the page from the database. What else can I do to get this BlogID number to keep getting passed all the way to the edit page so the correct data displays? Thanks.

                        Andy
                        • 9. Re: logging into an edit page
                          saurav Pandit Level 1

                          Hi jamie61880,

                           

                          Wil you please put a dump of url scope before this line of codes.

                           

                          <cfdump var="#url#" lable="url"><cfabort>

                          <cfif isDefined("url.blogid") />

                               <cfset blogID = url.blogID />

                          <cfelse>

                               <cfset blogID = 0 />                           

                          </cfif>

                           

                          It will help me to know what are the params that are coming through url.

                           

                          Thanks

                          • 10. Re: logging into an edit page
                            Ashish Todon Level 1

                            Andy,

                               Please Check if you are following these step :-

                            1. After clicking on your mailed url (http://www.ironwoodelectronics.com/blog/edit_blog.cfm?BlogID=63)             
                            2. You will be navigated to your website. First you might be checking for session exist or not. Please go to that code and check.
                            3. If session does not exist, you might be redirecting your page to login. That place we need some editing

                                   May be you are doing like this after session checking

                                      <cflocation url="http://www.ironwoodelectronics.com/Blog_Login/login.cfm" />

                                                    OR

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

                                    replace it by

                                       <cflocation url="http://www.ironwoodelectronics.com/Blog_Login/login.cfm?blogId=#URL.blogId#" />

                                                     OR

                                        <cflocation url="Blog_Login/login.cfm?blogId=#URL.blogId#" />

                                4. This will navigate user to login page with blogId in URL

                                 5. If uptill here it is correct we are on right way.

                                6. If you have action attribute in you login form. you can make some modification

                                    if we have acition with out url id please add it like:-

                                      <cfform action="action_page.cfm?blogID=#URL.blogId#">

                                         :   //your code

                                          :

                                      </Cffrom>

                                 7. If you are not having action attribute(skip step 6) in form then please add it.

                                    like:-

                                      <cfform action="login.cfm?blogID=#URL.blogId#">

                                         :   //your code

                                         :

                                      </Cffrom>

                             

                                8. Now as user insert username and password and click sumit. you might be doing some validation and authentication checking

                                     there on success while you are redirecting to edit_blog.cfm . here we need some modification  

                                       <cflocation url="http://www.ironwoodelectronics.com/Blog_Login/login.cfmhttp://www.ironwoodelectronics.com/blog/edit_blog.cfm" />

                                                    OR

                                       <cflocation url="blog/edit_blog.cfm" />

                                    replace it by

                                       <cflocation url="http://www.ironwoodelectronics.com/blog/edit_blog.cfm?blogId=#URL.blogId#" />

                                                    OR

                                       <cflocation url="blog/edit_blog.cfm?blogId=#URL.blogId#" />

                                9. Now step 8 will redirect us to edit hom page and please check if we got bogid or not in URL.

                             

                            Thanks

                            • 11. Re: logging into an edit page
                              jamie61880 Level 1

                              Ashish,

                                     I did your suggestions above and I am able to see the BlogID number on the Login page now at least. But I still cannot get it to work correctly on the edit page after the user logs in. It says the BlogID is undefined in the URL. I thought by changing everything you told me to change would fix this, unless I'm still doing something else wrong. Once the user logs in, I do have the login page going to a Validate page. On this Validate Page is where this error is happening. It says:

                               

                               

                              The error occurred in H:\Ironwoodelectronics/Blog_Login\validate.cfm: line 93

                               

                              91 :

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

                              93 : <cflocation url="../blog/edit_blog.cfm?BlogID=#URL.blogId#">

                               

                                   Do I have to pass the URL in the Login Button somehow? If I put the dump var code on the validate page:

                              <cfdump var="#url#" lable="url"><cfabort>, I get this: struct [empty]

                               

                              I do have the login buttons set up as Javascript like this:

                               

                               

                              <script type="text/javascript">

                               

                              function englogin()

                              {

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

                              document.foo.app_login.value="no"

                              document.foo.action ="validate.cfm";

                              document.foo.submit();

                              }

                               

                               

                              function applogin()

                              {

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

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

                              document.foo.action ="validate.cfm";

                              document.foo.submit();

                              }

                               

                              </script>

                               

                               

                              <cfinput type="button" name="submitBtn" onclick="englogin()" value="Engineer Login">

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

                               

                              <cfinput type="hidden" name="eng_login">

                              <cfinput type="hidden" name="app_login">

                               

                                  How do I fix this from after the user logs in, to the edit page? Thanks for your help.

                               

                              Andy

                              • 12. Re: logging into an edit page
                                jamie61880 Level 1

                                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

                                • 13. Re: logging into an edit page
                                  jamie61880 Level 1

                                  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