Skip to main content
Participant
November 3, 2011
Question

How to validate textbox in coldfusion8.0

  • November 3, 2011
  • 1 reply
  • 502 views

Hello,this is Mr-Bat with another problem. The problem is this time with my login page code when i type nothing in textbox then also on clicking login button i can acess homepage.the code for login is as folows:

<cfform action="Home.cfm" method="post" name="LoginForm.cfm" >

<table align="center" border="1" bgcolor="#CCCCCC" bordercolor="#000000" cellpadding="3" cellspacing="2">

<tr bgcolor="#FF9797">

  <th colspan="2"><div align="center"><strong>Login</strong></div></th>

  </tr>

<tr>

<th>Login name </th>

<td><div align="center">

  <cfinput type="text" name="Login" size="20" maxlength="35"  required="yes">

</div></td>

</tr>

<tr>

<th>Password</th>

<td><div align="center">

  <cfinput type="password" name="password" size=20 maxlength="35" required="yes">

</div></td>

</tr>

<tr>

  <th height="28" colspan="2">

    <div align="center">

      <cfinput type="submit" name="Login" value="Login" onClick="">   

      <cfinput type="submit" name="Cancel" value="Cancel" onClick="">

      </div></th>

</tr>

  </table>

</cfform>

<cfif isdefined("Form.Login")>

          <cfquery name="Checkout" datasource="CFM" maxrows="1">

                    Select Log_name,Log_pass from dbo.Login where Log_name='#form.Login#'

          </cfquery>

          <cfif checkout.recordcount NEQ 0 >

                    <cfif #Log_name# eq #form.Login# and #Log_pass# eq #form.password#>

                              <a href="Home.cfm"></a>

                              <cfelse>

                                        <cfoutput> Enter Valid Username or Password</cfoutput>

                    </cfif>

          </cfif>

</cfif>

<!--- Check to see if the session variable exists,if not set it.--->

<cfparam name="session.IsLoggedIn" default="N"/>

<!---Check to see if the session variable exists,if not  redirect them to the login page--->

<cfif IsDefined("session.IsLoggedIn") EQUAL "N0">

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

</cfif>

Help as eaerly as possible.

This topic has been closed for replies.

1 reply

Inspiring
November 3, 2011

Add a message attribute to the cfinput tags that have required="yes".

Inspiring
November 3, 2011

You can also take advantage of the built in CF server side validation syntax:

<input type="hidden" name="Login_required" value="Please enter a value into the Login name field">

<input type="hidden" name="password_required" value="Please enter a value into the Password field">

It generates a REALLY (no offence meant, Adobe forum monitors) ugly results page, but it is a quick and dirty way to make sure no one sidesteps around your client-side JS validation.

Hope that helps,

- Michael