validating a field from records in a database
Can anyone else help with my problem? One of the users gave me some help but I'm still having a problem. I'm open for suggestions on another approach or help with the one I'm attempting. Thanks in advance!! -----Original Message----- From: Beaudette, Sheree To: 'stuart.nicholson@wirelessdatanz.com' Sent: 10/18/01 8:22 AM Subject: FW: [Zope] validating a field with records in a database It's me again. Ok, I tried what you said and it seems logical but I keep getting the so informative 'Error on Page' javascript error. Here's what I have. <SCRIPT LANGUAGE="JavaScript"> var listofids = new Array(); <dtml-in clsqGetObligorUniqueIDs> listofids[<dtml-var sequence-index>] = <dtml-var obl_UniqueID>; </dtml-in> function uniqueid(uniqueIDfield) var i = 0; do if (listofids[i]==uniqueIDfield) alert ("This ID already exists."); i=listofids.length; } } while (++i < listofids.length); } </SCRIPT> then in my form I have it calling this function <INPUT TYPE="TEXT" NAME="obl_UniqueID" onChange="uniqueid(obl_UniqueID)" tabindex="1" size="10" value=''> I tried a couple of different things... I wasn't sure how to refer to the array. Do I pass it in on the onChange event? I tried that and still got the error. So if this is the case how do I refer to it? Also I printed a list of current variables and listofids isn't there. When would this be populated? I think I'm just missing a piece or two. Hope you can help! Thanks! Sheree Beaudette, AVP Applications Support Analyst Banknorth Group, Commercial Services 207-828-7133 Fax: 207-756-6990 sbeaudette@banknorth.com -----Original Message----- From: Stuart Nicholson [mailto:stuart.nicholson@wirelessdatanz.com] Sent: Wednesday, October 17, 2001 10:41 PM To: Sheree Beaudette Subject: RE: [Zope] validating a field with records in a database I'm building similar solutions using Zope/DTML/Javascript. If you want to populate a Javascript array to use on the client side for form validation, I believe you want something more like: <script language="javascript"> var listofids = new Array(); <dtml-in clsqGetObligorUniqueIDs> listofids[<dtml-var sequence-index>] = <dtml-var obl_UniqueID>; </dtml-in> </script> And then use this array for your Javascript form validation. I'm fairly certain this isn't the best solution as you're building a big static array (depending on the number of entries in your MySQL table) in Javascript. But I think it's the only option if you want to do validation all on the same form (without redirecting and validating on the Zope server). The trick here of course is to distinguish the Zope server side DTML scripting from the Web browesr client side Javascript. Hope that helps? Stuart Nicholson Software Engineer Wireless Data -----Original Message----- From: Sheree Beaudette [mailto:sheree@psouth.net] Sent: Thursday, October 18, 2001 3:25 PM To: zope@zope.org Subject: [Zope] validating a field with records in a database I hope someone can help with this. I'm under the gun to get this done... the concept of what I have to do is... I have a form with several fields on it. all of the data, once submitted, goes into 1 MySQL table called t_Obligors. 1. the user will enter an id (obl_UniqueID) into an input field 2. as soon as they enter it I want the data in the field to be verified that a prior Unique ID does not exist (probably onChange event) by searching the t_Obligors table (I have a sql query called cldmGetObligorUniqueIDs) at this point obl_UniqueID is not the primary key and I'm not sure if I want it to be because the database was not originally set up with this field so it would be a lot of work to go back and re-populate data. (I'm also under a tight deadline) 3. to do the actual event I was using Javascript (this one would occur on the onChange event) for my form validation since that's what I know and I don't have time at this point to learn something new since it needs to be done very quickly. 4. if there's a match they get a message saying that ID is already in use so please enter another Here was a thought I had been playing with: below sets an increment, i, and attempts to populate an array for future use in my Javascript but I cannot get the array to increment, I don't even know how to refer an array (or whatever it's called) in Zope. <dtml-call "REQUEST.set('i', 0)"> - sets increment to zero <dtml-in clsqGetObligorUniqueIDs> - loops through the query and gets all Unique IDs <dtml-call "REQUEST.set('listofids.[i]',obl_UniqueID)"> - trying to set the array with unique IDs <dtml-call "REQUEST.set('i', i+1)"> </dtml-in> this was only one thought, I'm open for suggestions... Thanks! _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Hi, Why don't you just create a unique ID on the server side? Let the user add a part of the ID that must be readable, and then send it to the server. There you can use something like this: import random, string bad =' ()[]{}ÄÅÁÀÂÃäåáàâãÇçÉÈÊËéèêëæÍÌÎÏíìîïÑñÖÓÒÔÕØöóòôõøSsßÜÚÙÛüúùûÝYýÿ??' good='_______AAAAAAaaaaaaCcEEEEeeeeeIIIIiiiiNnOOOOOOooooooSssUUUUuuuuYYyyZz' TRANSMAP=string.maketrans(bad, good) def makeId(anId): anId = string.translate(anId, TRANSMAP) + str(random.random() * 1000000000) return anId If there is no special reason that you must have your user select an absolutely uniqe id then I think this is the better approach. If writing the function is beyond your means, I can send you a reddy to go script. Just tell me Robert ----- Original Message ----- From: "Sheree Beaudette" <sheree@psouth.net> To: <zope@zope.org> Sent: Sunday, October 21, 2001 4:12 PM Subject: [Zope] validating a field from records in a database
Can anyone else help with my problem? One of the users gave me some help but I'm still having a problem. I'm open for suggestions on another approach or help with the one I'm attempting.
Thanks in advance!!
-----Original Message----- From: Beaudette, Sheree To: 'stuart.nicholson@wirelessdatanz.com' Sent: 10/18/01 8:22 AM Subject: FW: [Zope] validating a field with records in a database
It's me again.
Ok, I tried what you said and it seems logical but I keep getting the so informative 'Error on Page' javascript error.
Here's what I have.
<SCRIPT LANGUAGE="JavaScript"> var listofids = new Array(); <dtml-in clsqGetObligorUniqueIDs> listofids[<dtml-var sequence-index>] = <dtml-var obl_UniqueID>; </dtml-in>
function uniqueid(uniqueIDfield)
var i = 0; do
if (listofids[i]==uniqueIDfield)
alert ("This ID already exists."); i=listofids.length; } } while (++i < listofids.length); } </SCRIPT>
then in my form I have it calling this function
<INPUT TYPE="TEXT" NAME="obl_UniqueID" onChange="uniqueid(obl_UniqueID)" tabindex="1" size="10" value=''>
I tried a couple of different things...
I wasn't sure how to refer to the array. Do I pass it in on the onChange event? I tried that and still got the error. So if this is the case how do I refer to it?
Also I printed a list of current variables and listofids isn't there. When would this be populated?
I think I'm just missing a piece or two.
Hope you can help! Thanks!
Sheree Beaudette, AVP Applications Support Analyst Banknorth Group, Commercial Services 207-828-7133 Fax: 207-756-6990 sbeaudette@banknorth.com
-----Original Message----- From: Stuart Nicholson [mailto:stuart.nicholson@wirelessdatanz.com] Sent: Wednesday, October 17, 2001 10:41 PM To: Sheree Beaudette Subject: RE: [Zope] validating a field with records in a database
I'm building similar solutions using Zope/DTML/Javascript. If you want to populate a Javascript array to use on the client side for form validation, I believe you want something more like:
<script language="javascript"> var listofids = new Array(); <dtml-in clsqGetObligorUniqueIDs> listofids[<dtml-var sequence-index>] = <dtml-var obl_UniqueID>; </dtml-in> </script>
And then use this array for your Javascript form validation.
I'm fairly certain this isn't the best solution as you're building a big static array (depending on the number of entries in your MySQL table) in Javascript. But I think it's the only option if you want to do validation all on the same form (without redirecting and validating on the Zope server). The trick here of course is to distinguish the Zope server side DTML scripting from the Web browesr client side Javascript.
Hope that helps?
Stuart Nicholson Software Engineer Wireless Data
-----Original Message----- From: Sheree Beaudette [mailto:sheree@psouth.net] Sent: Thursday, October 18, 2001 3:25 PM To: zope@zope.org Subject: [Zope] validating a field with records in a database
I hope someone can help with this. I'm under the gun to get this done...
the concept of what I have to do is...
I have a form with several fields on it. all of the data, once submitted, goes into 1 MySQL table called t_Obligors.
1. the user will enter an id (obl_UniqueID) into an input field
2. as soon as they enter it I want the data in the field to be verified that a prior Unique ID does not exist (probably onChange event) by searching the t_Obligors table (I have a sql query called cldmGetObligorUniqueIDs) at this point obl_UniqueID is not the primary key and I'm not sure if I want it to be because the database was not originally set up with this field so it would be a lot of work to go back and re-populate data. (I'm also under a tight deadline)
3. to do the actual event I was using Javascript (this one would occur on the onChange event) for my form validation since that's what I know and I don't have time at this point to learn something new since it needs to be done very quickly.
4. if there's a match they get a message saying that ID is already in use so please enter another
Here was a thought I had been playing with: below sets an increment, i, and attempts to populate an array for future use in my Javascript but I cannot get the array to increment, I don't even know how to refer an array (or whatever it's called) in Zope.
<dtml-call "REQUEST.set('i', 0)"> - sets increment to zero <dtml-in clsqGetObligorUniqueIDs> - loops through the query and gets all Unique IDs <dtml-call "REQUEST.set('listofids.[i]',obl_UniqueID)"> - trying to set the array with unique IDs <dtml-call "REQUEST.set('i', i+1)"> </dtml-in>
this was only one thought, I'm open for suggestions...
Thanks!
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Robert Rottermann -
Sheree Beaudette