Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created April 12, 2023 12:27
Show Gist options
  • Save bennadel/16b101587fad08bb4004ca1d9c7f97f4 to your computer and use it in GitHub Desktop.
Save bennadel/16b101587fad08bb4004ca1d9c7f97f4 to your computer and use it in GitHub Desktop.

Revisions

  1. bennadel created this gist Apr 12, 2023.
    57 changes: 57 additions & 0 deletions index.cfm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    <cfscript>
    param name="form.name" type="string" default="Tricia";
    param name="form.action" type="string" default="";
    </cfscript>
    <cfoutput>

    <!-- BEGIN: Form. -->
    <form id="myForm" method="post" action="#cgi.script_name#">
    <input
    type="text"
    name="name"
    value="#encodeForHtmlAttribute( form.name )#"
    />
    <button type="submit" name="action" value="greet">
    Greet
    </button>
    </form>
    <!-- END: Form. -->

    <hr />

    <p>
    These buttons are <strong>outside the form</strong> container. However, they are
    using the <code>form</code> attribute to associate with an existing form on the
    page.
    </p>
    <p>
    <button type="submit" form="myForm" name="action" value="insult">
    Insult
    </button>
    <button type="submit" form="myForm" name="action" value="flatter">
    Flatter
    </button>
    </p>

    <!--- Output message if we have all the submitted form data. --->
    <cfif ( form.name.len() && form.action.len() )>
    <hr />
    <p>
    <strong>[action: #encodeForHtml( form.action )#]</strong>
    <cfswitch expression="#form.action#">
    <cfcase value="greet">
    Good morning, #encodeForHtml( form.name )#, I hope all is well.
    </cfcase>
    <cfcase value="insult">
    Hey #encodeForHtml( form.name )#, you are a poo-face!
    </cfcase>
    <cfcase value="flatter">
    Wow #encodeForHtml( form.name )#, you look amazing!
    </cfcase>
    </cfswitch>
    </p>
    </cfif>

    </cfoutput>
    6 changes: 6 additions & 0 deletions snippet-1.cfm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <form id="myForm">
    ...
    </form>
    <button type="submit" form="myForm">
    Submit Form
    </button>