Skip to main content
Known Participant
April 14, 2014
Question

running a script and creating a link?

  • April 14, 2014
  • 2 replies
  • 1054 views

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

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    April 14, 2014

    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.

    Known Participant
    April 14, 2014

    what does

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

    BKBK
    Community Expert
    Community Expert
    April 14, 2014

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

    Dave Ferguson
    Participating Frequently
    April 14, 2014

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