Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to have a validation check

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Hi,

I want to have a check function on an item, whether this items is belong to an Existing item or a New item in the database. My idea is:

1.enter an item number from the form page.
2.then have a check on the item number.
3.if the item is existing, it'll link to the Update action form
4.or if the item is new, then it'll link to Add action form.

Thanks in advance....
 
You would need a page that had a form for the user to enter the item number. That form would submit to a page containing the code below:
Code:
<cfquery name=&quot;qryCheckItem&quot; datasource=&quot;myDSN&quot;>
  SELECT *
  FROM tblItems
  WHERE itemNumber = <cfqueryparam value=&quot;#FORM.itemNumber#&quot; cfsqltype=&quot;CF_SQL_INTEGER&quot;> 
</cfquery>
<cfif qryCheckItem.recordcount EQ 0>
  <!---
    Insert &quot;Add&quot; form here
  --->
<cfelse>
  <!---
    Insert &quot;Update&quot; form here
    (Note: you already have the data stored in qryCheckItem)
  --->
</cfif>
You would then need additional form handler pages to handle the add and update forms.

Hope this helps!
 
Hi, Pcorreia

It's works....Thanks. But I've one problem it can link to the update form but it can't open the update form. Add form is functioned. Here's my program:

AddUpdateChk.cfm:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<CFinclude template=&quot;../template/header1.cfm&quot;>
<cfquery name=&quot;chkpartno&quot; datasource=&quot;JESEng&quot;>
SELECT partno
FROM Film
WHERE partno = <cfqueryparam value=&quot;#form.partno#&quot;
cfsqltype=&quot;CF_SQL_VARCHAR&quot;
MAXLENGTH=&quot;15&quot;>
</cfquery>
<cfif chkpartno.recordcount EQ 0>
<form action=&quot;filmAdd.cfm&quot; method=&quot;post&quot;>
<font color=&quot;#993399&quot;><strong>PLEASE WAIT....WHILE PROCESSING</strong></font>
<meta http-equiv=refresh content=&quot;2;url=..\Film\filmAdd.cfm&quot;>
</form>
<cfelse>
<form action=&quot;filmUpdate.cfm&quot; method=&quot;post&quot;>
<font color=&quot;#993399&quot;><strong>PLEASE WAIT....WHILE PROCESSING</strong></font>
<meta http-equiv=refresh content=&quot;2;url=..\Film\filmUpdate.cfm&quot;>
</form>
</cfif>

And filmUpdate.cfm
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<CFinclude template=&quot;../template/header1.cfm&quot;>
<style>
.bu{ background-color: #33ff99 ; color=#330000}
</style>

<CFQUERY DATASOURCE=&quot;JESEng&quot; NAME=&quot;ReFilm&quot;>
SELECT partno, partname, Rdate, subno, refno, rmk, Rneng, Org
FROM Film
WHERE partno = '#form.partno#'
</CFQUERY>

<CFOUTPUT QUERY=&quot;ReFilm&quot;>
<html>
<head>
<title>FILM/SAMPLE/MECHA SPEC MASTER</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<center>
<body TEXT=&quot;BLUE&quot;>
<h1>FILM/SAMPLE/MECHA SPEC MASTER - #partno#</h1>
</center>

<FORM ACTION=&quot;filmUpdateAction.cfm&quot; METHOD=&quot;POST&quot;>

<!--<INPUT TYPE=&quot;hidden&quot; NAME=&quot;partno&quot; VALUE=&quot;#partno#&quot;>-->

<P>
Part No.:
<INPUT TYPE=&quot;text&quot; NAME=&quot;partno&quot; SIZE=&quot;20&quot; MAXLENGTH=&quot;20&quot; VALUE=&quot;#TRIM(ReFilm.partno)#&quot;>
<BR>
Part Name:
<INPUT TYPE=&quot;text&quot; NAME=&quot;partname&quot; SIZE=&quot;20&quot; MAXLENGTH=&quot;20&quot; VALUE=&quot;#TRIM(ReFilm.partname)#&quot;>
<BR>
Received Date:
<INPUT TYPE=&quot;text&quot; NAME=&quot;Rdate&quot; SIZE=&quot;10&quot; MAXLENGTH=&quot;10&quot; VALUE=&quot;#TRIM(ReFilm.Rdate)#&quot;>
<BR>
Sub No.:
<INPUT TYPE=&quot;text&quot; NAME=&quot;subno&quot; SIZE=&quot;20&quot; MAXLENGTH=&quot;15&quot; VALUE=&quot;#TRIM(ReFilm.subno)#&quot;>
<BR>
Reference No.:
<INPUT TYPE=&quot;text&quot; NAME=&quot;refno&quot; SIZE=&quot;20&quot; MAXLENGTH=&quot;15&quot; VALUE=&quot;#TRIM(ReFilm.refno)#&quot;>
<BR>
Remarks:
<INPUT TYPE=&quot;text&quot; NAME=&quot;rmk&quot; SIZE=&quot;20&quot; MAXLENGTH=&quot;15&quot; VALUE=&quot;#TRIM(ReFilm.rmk)#&quot;>
<BR>
RND/ENG:
<INPUT TYPE=&quot;text&quot; NAME=&quot;Rneng&quot; SIZE=&quot;2&quot; MAXLENGTH=&quot;2&quot; VALUE=&quot;#TRIM(ReFilm.Rneng)#&quot;>
Origin:
<INPUT TYPE=&quot;text&quot; NAME=&quot;Org&quot; SIZE=&quot;2&quot; MAXLENGTH=&quot;2&quot; VALUE=&quot;#TRIM(ReFilm.Org)#&quot;>
<p>

<INPUT TYPE=&quot;submit&quot; NAME=&quot;Update&quot; VALUE=&quot;Update Part No&quot; class=&quot;bu&quot;>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;Delete&quot; VALUE=&quot;Delete Part No&quot; class=&quot;bu&quot;>
<INPUT TYPE=&quot;reset&quot; VALUE=&quot;Clear&quot; class=&quot;bu&quot;>
</form>
</CFOUTPUT>

</body>
</html>
<cfinclude template=&quot;../template/footer.cfm&quot;>
 
I think <META> tags are only allowed in the head of an HTML document -- that may be why the redirect isn't working. You have a couple of options here:[ol][li]Instead of using redirects, put the code for each of the forms right in your AddUpdateChk.cfm page, between the <CFIF> tags. This reduces the number of pages you have to maintain. Basically, the user sees AddUpdateChk.cfm as a form page which shows different content based on whether the item number they entered exists or not.[/li]
[li]If that gets too complicated, keep your separate pages for the different input forms but <cfinclude> the appropriate one into the AddUpdateChk.cfm page depending on the result of the chkpartno query. The result to the user is the same as in the first option, but you get to separate the code out into distinct pages that may make more sense to you.[/li]
[li] If you're really determined to redirect the user to another page, you can use <cflocation> instead of a meta tag to redirect the user to the appropriate page. This tag can be used anywhere in the page, but you won't see any output from the page in the browser because <cflocation> writes an HTTP header that tells the browser to go directly to another page, and doesn't send any additional content.[/li][/ol]
Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top