EasyCFM.COM ColdFusion Forums / Coding Help! / Forms

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Forms -- page: 1 2

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

specific
04-25-2006 @ 2:44 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

I never got Problems with forums, but this Time, I habe a form fields which are creating an obstacle in my way, I want to insert he items in the database, upon checking of the username, password and cirfirm password and all relevant fields, but It checks for one error and skips all other fields, and directly enters the data in the database with null values, help me outta this, the code of the form and processing page is below:

form.cfm page

<form method="POST" action="new_0.cfm">
  <table width="350" border="0" align="center" cellpadding="2">
    <tr>
      <td colspan="3" nowrap><div align="center" class="legal style1"><strong>. : Registration : . </strong></div></td>
    </tr>
    <tr>
      <td colspan="3" nowrap> </td>
    </tr>
    <tr>
      <td colspan="3" nowrap><div align="center">
       <cfif action IS "p">
       Password Mismatch
       <cfelseif action IS "f1">
       Your real Name Required
       <cfelseif action IS "l">
       Email Address not Valid
       <cfelseif action IS "i">
       Image Verification failed
       <cfelseif action IS "a">
       Username Already taken
       <cfelseif action IS "r">
       Thanks For registering
       </cfif>
       </div></td>
    </tr>
    <tr>
      <td align="right" nowrap class="sidebar"> Name : </td>
      <td colspan="2" nowrap>
       <input name="fullname" type="TEXT" size="20" maxlength="35" ></td>
    </tr>
    <tr>
      <td width="121" nowrap>
        <div align="RIGHT" class="sidebar">User :</div>      </td>
      <td colspan="2" nowrap><input name="username" type="TEXT" size="20" maxlength="20">      </td>
    </tr>
    <tr>
      <td nowrap>
        <div align="RIGHT" class="sidebar">Email :</div>      </td>
      <td colspan="2" nowrap><input name="email" type="TEXT" size="20" maxlength="35">      </td>
    </tr>
    <tr>
      <td align="right" nowrap class="sidebar">Password :</td>
      <td colspan="2" nowrap><input name="password" type="PASSWORD" size="20" maxlength="20"></td>
    </tr>
    <tr>
      <td nowrap>
        <div align="RIGHT" class="sidebar">Confirm Password : </div>      </td>
      <td colspan="2" nowrap><input name="password2" type="PASSWORD" size="20" maxlength="20">      </td>
    </tr>
    <tr>
      <td valign="top" nowrap>
        <div align="RIGHT" class="sidebar">Comments:</div>      </td>
      <td colspan="2" nowrap>
       <textarea name="comments" cols="30" rows="6" wrap ="VIRTUAL"></textarea></td>
    </tr>
    
    <tr>
      <td nowrap> </td>
      <td colspan="2" nowrap>
        <div align="LEFT">
          <input type="SUBMIT" value="Submit">
          <input name="RESET" type="RESET" value="Reset" />
        </div>      </td>
      </tr>
  </table>
</form>


here is Processing.cfm

<!--- Email Validation Goes Here --->
<cfset dot = 0>
<cfset at2 = 0>
<cfset at = Find("@",Form.email)>
<cfif at GT 0>
     <cfset at2 = Find("@",Form.email,at+1)>
     <cfset dot = Find(".",Form.email,At+1)>
</cfif>

<cfif  Not IsDefined("form.fullname")>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Not IsDefined("form.username")>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Not IsDefined("form.password")>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Not IsDefined("form.email")>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Not IsDefined("form.comments")>
     <cflocation addtoken="no" url="new.cfm">

<cfelse>
<cfquery datasource="#dbsource#" name="check"
username="#dbsource_username#" password="#dbsource_password#">
select username,email from login
where username = '#form.username#'
</cfquery>
     <cfquery datasource="#dbsource#"
               username="#dbsource_username#" password="#dbsource_password#">
                      INSERT INTO login (username, password, password2,
                    email, FullName, Comments) VALUES (
                    '#FORM.username#','#FORM.password#',
                    '#FORM.password2#','#FORM.email#',
                     '#FORM.fullname#','#FORM.comments#')
                      </cfquery>
     <cflocation url="new.cfm?action=r" addtoken="no">
     </cfif>

CJ
04-25-2006 @ 2:50 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

because you're using isDefined().

the form fields will always be defined (unless they're checkboxes or radio buttons with none selected...but don't worry about that for now).

do a <cfdump var="#form#"> on your action page and you'll see that your form fields DO exist.  the values are just empty strings.

so instead of isDefined(), you want to check the length of the value.

<cfif len(trim(form.foo)) EQ 0>
     you have no foo!
</cfif>


-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

specific
04-25-2006 @ 3:00 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

same problem with function u told me, also i want to remeber the fields user already filled in

CJ
04-25-2006 @ 3:01 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

show me the code you're using now on your process page.

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

specific
04-25-2006 @ 3:07 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

<!--- Email Validation Goes Here --->
<cfset dot = 0>
<cfset at2 = 0>
<cfset at = Find("@",Form.email)>
<cfif at GT 0>
     <cfset at2 = Find("@",Form.email,at+1)>
     <cfset dot = Find(".",Form.email,At+1)>
</cfif>
<cfif Len(Trim(form.fullname)) EQ 0>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Len(Trim(form.username)) IS 0>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Len(Trim(form.email)) IS 0>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Len(Trim(form.password)) IS 0>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Len(form.password) NEQ Len(form.cpassword)>
     <cflocation addtoken="no" url="new.cfm">
<cfelse>
<cfquery datasource="#dbsource#" name="check"
username="#dbsource_username#" password="#dbsource_password#">
select username,email from login
where username = '#form.username#'
</cfquery>
     <cfif check.username eq #form.username#>
     Sorry Username already taken
     <cfelse>
     <cfquery datasource="#dbsource#"
               username="#dbsource_username#" password="#dbsource_password#">
                      INSERT INTO login (username, password, password2,
                    email, FullName, Comments) VALUES (
                    '#FORM.username#','#FORM.password#',
                    '#FORM.password2#','#FORM.email#',
                     '#FORM.fullname#','#FORM.comments#')
                      </cfquery>
     <cflocation url="new.cfm?action=r" addtoken="no">
     </cfif>
     </cfif>

CJ
04-25-2006 @ 3:11 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

that looks right to me.

try doing this:

<cfif Len(Trim(form.fullname)) EQ 0>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Len(Trim(form.username)) IS 0>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Len(Trim(form.email)) IS 0>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Len(Trim(form.password)) IS 0>
     <cflocation addtoken="no" url="new.cfm">
<cfelseif Len(form.password) NEQ Len(form.cpassword)>
     <cflocation addtoken="no" url="new.cfm">
<cfelse>
     <cfdump var="#form#"><cfabort>
</cfif>

Basically what we're looking for here is that -if- all of your validation checks are passed, you will see the form scope dumped and be able to verify that 'fullname' has a length, 'username' has a length, etc.

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

specific
04-25-2006 @ 3:23 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

now its working, but what happens sometimes to these forms, they behave so improperly like the code could be right but a develper goes through the pain of headche to solve it, anyways, it is solved now, and is ther any way i should test the email address in easy way and Should remeber the details of the person who is filling the form, like when an error occures he should go back and filled the missing fields only, the firelds he should have filled in, should be there with already the value he outputted, i know its being use of cfparam tag, but never tried, it, could you help it anyways

CJ
04-25-2006 @ 3:28 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

the most effective way to maintain the user's data (IMO) is to create a structure in the session scope.

call it session.myForm (this would be created before the user gets to the form page...maybe in an Application.cfm).

let's say your form has 3 fields:

firstName
lastName
emailAddress

so you would create:

session.myForm.firstName = ""
session.myForm.lastName = ""
session.myForm.emailAddress = ""

now on your form page, you would give each field a value:

<input type="text" name="firstName" value="#session.myForm.firstName#" />

on your process page, you would set all of the fields that have been filled out properly (that pass validation) to your session.myForm structure.

this way when you redirect the user back to the form, the value of a given form field (such as #session.myForm.firstName#) will still either be blank, or will be the value you assigned to it on the processing page.

let me know if that makes sense.



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

specific
04-25-2006 @ 3:42 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

not working you said as


CJ
04-25-2006 @ 3:45 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

i'm sorry but you're really going to need to make an effort to be more clear in a few things.

what specifically are you asking?
what specifically is not working?
how is it not working?  is there an error?  if so, what error.  at which point?

"not working" really doesn't give me a lot to go on as far as helping you further.



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

PAGE: 1 2

Website Designed and Developed by Pablo Varando.