...

View Full Version : Desperate... Need to validate form field against database



misterzr
06-04-2005, 05:22 PM
Please Help..............

I need to validate a form field against a list of numbers in a database, This should be simple but I can't figure it out..

Here is the code for the recordset, the items are in the ITLITM column(16,000 lines)
I need to run a check on each field(32 times) when they advance to the next field.(onBlur or onChange)


<%
Dim RS_NumCheck1
Dim RS_NumCheck1_numRows

Set RS_NumCheck1 = Server.CreateObject("ADODB.Recordset")
RS_NumCheck1.ActiveConnection = MM_JDE_DEV_STRING
RS_NumCheck1.Source = "SELECT IMLITM FROM TESTDTA.F4101"
RS_NumCheck1.CursorType = 0
RS_NumCheck1.CursorLocation = 2
RS_NumCheck1.LockType = 1
RS_NumCheck1.Open()

RS_NumCheck1_numRows = 0
%>

Thanks in advance

martin_narg
06-04-2005, 06:35 PM
I actually sat down and started to try and write a response to your post, but stopped when I realised there are too many ways to do what you want.

The code you have posted up is simply a database query that selects all the IMLITM (or ITLITM as you call it elsewhere in your post). However this should be more like what you are trying to do:


Dim RS_NumCheck1
Dim imlitmToCheck
imlitmToCheck = 13

Set RS_NumCheck1 = Server.CreateObject("ADODB.Recordset")
RS_NumCheck1.ActiveConnection = MM_JDE_DEV_STRING
RS_NumCheck1.Source = "SELECT imlitm FROM TESTDTA.F4101 WHERE imlitm=" & imlitmToCheck
RS_NumCheck1.CursorType = 0
RS_NumCheck1.CursorLocation = 2
RS_NumCheck1.LockType = 1
RS_NumCheck1.Open()

If RS_NumCheck1.EOF Then
'imlitmToCheck does not exist in TESTDTA.F4101
Else
'imlitmToCheck is already in TESTDTA.F4101
End If

RS_NumCheck1.Close()
Set RS_NumCheck1 = Nothing


One suggestion (and i can think of at least 3 others) might be to have this:

form page:


<script>
function openImlitmCheckWindow(imlitmToCheck) {
if( imlitmToCheck.length < 1 )
return;
else
window.open("popup.asp?imlitmToCheck="+imlitmToCheck);
}
</script>
<form name="frm" action="form_handler.asp" method="post">
<input type="text" name="txtImlitmtoCheck">
<input type="button" value="check imlitm" onclick="openImlitmCheckWindow(document.frm.txtImlitmtoCheck.value);">
</form>


popup page:


If Len(Request.QueryString("imlitmToCheck")) > 0 Then
Dim RS_NumCheck1

Set RS_NumCheck1 = Server.CreateObject("ADODB.Recordset")
RS_NumCheck1.ActiveConnection = MM_JDE_DEV_STRING
RS_NumCheck1.Source = "SELECT imlitm FROM TESTDTA.F4101 WHERE imlitm=" & Request.QueryString("imlitmToCheck")
RS_NumCheck1.CursorType = 0
RS_NumCheck1.CursorLocation = 2
RS_NumCheck1.LockType = 1
RS_NumCheck1.Open()

If RS_NumCheck1.EOF Then
Response.Write "imlitm not in database, ok to continue<br><a href=""javascript: window.close();"">Close window</a>"
Else
Response.Write "<scr"&"ipt>opener.document.frm.txtImlitmtoCheck.value = '';</scr"&"ipt>"
Response.Write "imlitm already exists in database, the form field has been cleared so you can enter in a new imlitm<br><a href=""javascript: window.close();"">Close window</a>"
End If

RS_NumCheck1.Close()
Set RS_NumCheck1 = Nothing
Else
Response.Write "No imlitm has been passed to this page to be checked"
End If


This would mean there was a button next to the imlitm input field on the form that would pop up a window that would check the database for the value in the imlitm form field. it would then either clear the text box if imlitm is found in the database or allow the user to continue if imlitm is not found in the database. It also displays the accompanying message of success or failure of the check and a link to close the window.

This is a very rough and ready script designed to show you how something might be done. Please don't forget that you always need to validate the form server side, don't rely solely on javascript for form validations as it can be easily bypassed.

I hope this helps someway in answering your question. There are many ways to do what you broadly ask for, please in your next postings be more specific and try and provide a much fuller amount of relevant code for us to look at ;-)

Cheers

m_n

misterzr
06-04-2005, 06:54 PM
what I was actually trying to do was verify that the number entered in the form field was in the database before continuing. I am using this form to input item numbers on page 1 and then on page 2 print the barcodes of the entered item numbers. I need to validate those items entered on page 1 before continuing to page 2.

Sorry for the lack of detail on first post

Here is complete code from page 1


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/JDE_DEV.asp" -->
<%
Dim RS_NumCheck1
Dim RS_NumCheck1_numRows

Set RS_NumCheck1 = Server.CreateObject("ADODB.Recordset")
RS_NumCheck1.ActiveConnection = MM_JDE_DEV_STRING
RS_NumCheck1.Source = "SELECT IMLITM FROM TESTDTA.F4101"
RS_NumCheck1.CursorType = 0
RS_NumCheck1.CursorLocation = 2
RS_NumCheck1.LockType = 1
RS_NumCheck1.Open()


%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="POST" name="form1">
<table width="672" height="960" border="1" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item1" type="text" id="item1" size="8" maxlength="8" >
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item2" type="text" id="item2" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item3" type="text" id="item3" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item4" type="text" id="item15" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
</tr>
<tr>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item5" type="text" id="item16" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item6" type="text" id="item6" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item7" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item8" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
</tr>
<tr>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item9" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item10" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item11" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item12" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
</tr>
<tr>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item13" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item14" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item15" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item16" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
</tr>
<tr>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item17" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item18" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item19" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>
<td width="42%" height="30">&nbsp;</td>
<td width="58%" height="30">&nbsp;</td>
</tr>
<tr>
<td height="25%" colspan="2">&nbsp;</td>
</tr>
</table></td>
<td width="168px" height="112px"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
<tr>
<td height="38" colspan="2"><div align="center">
<input name="item20" type="text" id="item18" size="8" maxlength="8">
</div></td>
</tr>
<tr>

</tr>
</table>
<p align="center">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
<%
RS_NumCheck1.Close()
Set RS_NumCheck1 = Nothing
%>

martin_narg
06-05-2005, 04:53 AM
Instead of the popup.asp page popping up in a new window. You could load it into an iframe with a height and with of 0 (ie invisible) and change any references from opener to parent (in popup.asp)

This would work well, and is more fully cross-browser supported than other methods, however you have so many checks needing to be done on the one page that it would be cleaner and more efficient to do the validation when the form gets posted. I know this isnt what you are looking for as a positive answer, but in this case I would suggest it. To make some 30 page requests each time querying the database is pretty time consuming, you can use SQL to do this much more efficiently.

What you are asking is quite tricky if one is not familiar with the programming languages being used. I would suggest checking the form with javascript that the form fields have something typed in them in the right format when it is submitted, but as for checking the database 30 odd times on the one page - i'd be inclined to steer clear of it.

m_n



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum