#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Element USERNAME is undefined in FORM


    Hey guys,

    I been working on this website where I have a multi level login system. Two pages are login and loginAction. On login page form looks like below.

    <cfform method="post" action="login_Action.cfm">
    <table align=center class=SingleBorder width="300"> <tr>
    <td colspan=2>
    <font size=4>Login</font><br>
    <img src="design/gifs/green_line.gif" alt="" />
    </td>
    </tr>
    <tr>
    <td align=right> Username: </td>
    <td align=left> <cfinput class="inputText" type=text name=username size="20">
    </td>
    </tr>
    <tr>
    <td align=right> Password: </td>
    <td align=left>
    <cfinput class="inputText" type=password name=password size="20">
    </td>
    </tr>
    <tr>
    <td>
    </td>
    <td align=left>
    <cfif isDefined("form.URLtogo")>
    <cfoutput>
    <cfinput name=URLtogo type=hidden value=#form.URLtogo#></cfoutput>
    <cfinput name=submit class="btn1" type=submit value=Login>
    <cfelseif isDefined("URL.URLtogo")>
    <cfoutput><cfinput name=URLtogo type=hidden value=#URL.URLtogo#>
    </cfoutput>
    <cfinput name=submit class="btn1" type=submit value=Login>
    </cfif> <br><br>
    </td>
    </tr>
    <tr>
    <td bgcolor=e5ae72 align=center colspan=2>
    <a href=forgot_Password.cfm> Forgot password?</a><br> Don't have an account?
    <a href="signup.cfm?URLtogo=#URLtogo#">Register Now</a>
    </td>
    </tr>
    </table>
    </cfform>


    and on loginAction page code in between HEAD tag looks like below.

    <cfquery name=login datasource="DBS1"> select * from TB_User where Username = '#form.username#' and Password = '#form.password#' </cfquery>


    Now every time when I login it throws me this error
    Element USERNAME is undefined in FORM
    However, if I refresh the page it shows as login was successful.

    In cfform name of the text field IS username and it is passing the value too, then why am I getting this error?

    thanks for help guys
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    Try putting quotes around "text" and "username" in your cfinput tag. If that doesn't work, add a <cfdump var="#form#"><cfabort> at the top of your action page to see what is actually in the form scope.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0
    Originally Posted by kiteless
    Try putting quotes around "text" and "username" in your cfinput tag. If that doesn't work, add a <cfdump var="#form#"><cfabort> at the top of your action page to see what is actually in the form scope.
    Thanks for your reply. I tried putting quotes without any luck. When I put that CFDUMP line as you said, if showed me table with name of all 4 variables that are passed from login page to Action page and also there values.

    Another thing to add, the same code works fine when I test it online. It logs user in and sends user to the page where s/he came from. Just how I wanted it to work. But gives error on local host!!
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    Not sure then. If it works on production then there must be something going on with your localhost system that is killing the form variables or redirecting you to the action page at some point where the form variables aren't being posted.

    You could also add a cfif block at the top of the action page that checks for the form variables, and if they aren't defined, redirect them back to the login page to try and ensure that the form variables are posted.

IMN logo majestic logo threadwatch logo seochat tools logo