8 Replies Latest reply on Apr 14, 2014 11:40 PM by BKBK

    running a script and creating a link?

    no_name_123 Level 1

      How can i create a new link on a page when a submit (button) is click?

      what i want to do is when that button is click then it will run that script(cfm file) and will create a link on the same page.

      so when

      <cfinput type="Submit" name="SubmitForm" value="Submit">(from answers.cfm)

      is click it will run the file in respnds.cfm and create a link in answers.cfm when you can click it and the respnds.cfm file will come up.

      any suggestion or maybe a article online (which i havent been able to find ) will help.

      thanks

        • 1. Re: running a script and creating a link?
          Dave Ferguson Level 3

          Dont use cfinput to create a button.  Use a button tag...  <button onclick="dosomething()">BUTTON</button>, or standard form input controls.

          • 2. Re: running a script and creating a link?
            BKBK Adobe Community Professional & MVP

            In what follows, I have assumed that answers.cfm and respnds.cfm are in the same directory.

             

            answers.cfm

             

            <!--- Make respnds.cfm the action page, so that the form submits to it --->

            <cfform action="respnds.cfm">

            </cfform>

             

            <!--- Place paragraph tag in answers.cfm, where you want link to be --->

            <p></p>

             

            respnds.cfm


            <cfif isDefined("form.SubmitForm")>

             

            <!--- Read the content of answers.cfm --->

            <cffile action="read" file="#expandPath('answers.cfm')#" variable="answer_cfm">

             

            <!--- Add link to <p></p> --->

            <cfset answer_cfm = replaceNoCase(answer_cfm,'<p></p>','<p><a href="someOtherpage.cfm">Some link text</a></p>')>

             

            <!--- Write content of answers.cfm back to disk --->

            <cffile action="write" file="#expandPath('answers.cfm')#" output="#answer_cfm#">

             

            </cfif>

             

            However, please be aware of the possible security hole. If you can write links to a CFM page by means of a form, so can anyone else.

            • 3. Re: running a script and creating a link?
              no_name_123 Level 1

              what does

              <a href="someOtherpage.cfm"> do? i have to have a someotherpage.cfm file?

              • 4. Re: running a script and creating a link?
                BKBK Adobe Community Professional & MVP

                no_name_123 wrote:

                 

                what does

                <a href="someOtherpage.cfm"> do? i have to have a someotherpage.cfm file?

                It is just a placeholder for the relative URL of the link. Put in it whatever you like, for example

                 

                <a href="respnds.cfm">

                • 5. Re: running a script and creating a link?
                  no_name_123 Level 1

                  oh ok so that just creates a new file , correct?

                  • 6. Re: running a script and creating a link?
                    no_name_123 Level 1

                    if i use <button onclick="dosomething()">BUTTON</button>

                    how will i call the dosomething?

                    • 7. Re: running a script and creating a link?
                      Dave Ferguson Level 3

                      dosomething would be some javascript function.   My feeing is that you are missing the basic fundamentals to build a web application.  You might want to read up on the basics first.  You might want to check out learncfinaweek.com for a good primer on building applications.

                      • 8. Re: running a script and creating a link?
                        BKBK Adobe Community Professional & MVP

                        no_name_123 wrote:

                        oh ok so that just creates a new file , correct?

                        No, it does not. The code I gave you does precisely what you wished to do in the beginning. I will explain it, step by step:

                         

                        1) You want to create a link in answers.cfm. So, place <p></p> at the location where you want the link.

                         

                        2) When you submit the form in the page answers.cfm, you want that action to open the file respnds.cfm. The usual way to do this is to make respnds.cfm the action of the form.

                        answers.cfm

                        <!--- Make respnds.cfm the action page, so that the form submits to it --->

                        <cfform action="respnds.cfm">

                        </cfform>

                        <!--- Place paragraph tag in answers.cfm, where you want link to be --->

                        <p></p>

                         

                        3) You want the link in answers.cfm to be created when the form is submitted. So the obvious place to put the code for creating the link is in the action page, respnds.cfm.

                        To create the link (in answers.cfm), you first have to read the content of answers.cfm.

                         

                        4) Next, you have to locate the string <p></p>, which you had previously placed in the page, and to replace it with <p><a href="respnds.cfm">Some link text</a></p>.  The link is in bold.

                         

                        5) You then have to write the modified content back to disk, as the modified file answers.cfm.

                         

                        respnds.cfm

                        <cfif isDefined("form.SubmitForm")>

                         

                        <!--- Read the content of answers.cfm --->

                        <cffile action="read" file="#expandPath('answers.cfm')#" variable="answer_cfm">

                         

                        <!--- Add link to <p></p> --->

                        <cfset answer_cfm = replaceNoCase(answer_cfm,'<p></p>','<p><a href="someOtherpage.cfm">Some link text</a></p>')>

                         

                        <!--- Write content of answers.cfm back to disk --->

                        <cffile action="write" file="#expandPath('answers.cfm')#" output="#answer_cfm#">

                         

                        </cfif>