I am new to coldfusion , please check my code below
<cfif isDefined("form.submit")>
<cfoutput>
<h3>hi</h3>
</cfoutput>
</cfif>
<cfform action="#CGI.SCRIPT_NAME#">
User Name:<cfinput type="Text" name="usr_nm"><br>
<cfinput type="Radio" name="access_flg" value="0">Admin
<cfinput type="Radio" name="access_flg" value="1">User</br>
<cfinput type="submit" name="submit" value="submit"><br>
</cfform>
But ,When I am clicking submit button ,I am expecting result as hi
I haven't see hi message, Is there any thing wrong in my code ,Any one please help me
Since you're new to ColdFusion, I'll give you some advice straight away:
1. Do not submit a form to the same page.
Submit the form to a separate page for processing. Reason being, as you get into more advanced applications, you'll need to restrict pages/URLs to only respond to an appropriate HTML Verb.
Your form page should respond to HTTP GET. Your form processing page should only respond to HTTP POST.
2. Do not use CFFORM.
The function of
CFFORM
is to create JavaScript validation and server-side interactions. This can easily be done with modern JavaScript libraries like3. Give your form elements an
ID
, as well as aNAME
.This allows easier reference to the form elements when using JavaScript.
4. Do not name your submit button "submit".
If you ever want to use JavaScript to submit a form, the function is
submit()
.For example:
$('#myForm').submit();
Having a form element named the same as a function will cause errors.
Here's
my_form.cfm
:5. You don't need to use
CFOUTPUT
unless you are rendering data from the server.Here's
my_form_action.cfm
:Even better: