Gossamer Forum
Home : Products : DBMan : Customization :

How can I make no one choose the options it is already taken by former user ?

Quote Reply
How can I make no one choose the options it is already taken by former user ?
Hi,
Someone would help me ?

I have two select option field at 22nd and 23rd.
These fields can't be blank.

If there are options like "aaa, bbb, ccc, ddd" at 22nd field,
and "111, 222, 333, 444" at 23rd field.

If "bbb and 333" has been taken by an user, how can I give to another user an error massage who wants to choose "bbb and 333" again ?

Thanks in advance.
Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Do you want to have multiple fields to be verified via the db_key variable in opps.cfg? If yes, then may be the following idea will help:

I have not tried this nor do I know if it will work. But may be you could put multiple field names in the db_key and set it up as an array (*), not a variable, like the following:

Code:
%db_key = (ID,Field1,Field2);

(*) An array allows you to specify multiple variables to be included.

Change Field1 and Field2 to the Field Names you want to track in the %db_def array. Make sure that you use the exact Field Name NOT the Field Number.

Then, in the default.cgi file, replace $db_key with %db_key.

I would suggest copying your files FIRST and then try to implement these changes. Also, may be other people or Carol will be able to provide in-depth codes that will address your question.

You could also try to search this forum for the following keywords: "db_key" or "validate".

Best regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 06, 1999).]

[This message has been edited by Eliot (edited August 06, 1999).]

[This message has been edited by Eliot (edited August 06, 1999).]
Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Multiple $db_keys won't work. There are too many places where $db_key is used that would have to be changed and I wouldn't know how to change them.

What you can do is this:

Set up a field for your key -- I'll call it ID for illustrative purposes. You can call it anything you want. Make it a hidden field and not required ("Not Null" =0).

Make your Field 22 and Field 23 required ("Not Null" =1).

In your .cfg file, set
$db_key = 'ID';
$db_key_track = 0;

If you're not using $db_auto_generate, be sure to have a hidden field for the ID field.

Now to the tricky part. In db.cgi, sub add_record, just after

Code:
($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);

add

Code:
if ($in{'Field 22'} and $in{'Field 23'}) {
$in{'ID'} = $in{'Field 22'} . $in{'Field 23'};
}

Be sure to enter the names of your fields instead of Field 22 and Field 23.


------------------
JPD





Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Sorry, koreags, for giving you a complicated and ineffective solution to your problem.

Sorry, JPDeni, for causing another mess. I guess I should keep quiet and change my handle to messcodes. Smile

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Not to worry, Eliot. Smile

I'm reminded of when I first started posting a lot of responses to people here. Just about every post had a mistake in it somewhere. (Now only about half of them do! Smile ) Alex would come in and correct me. It was a little hard on my ego at first, but at the same time I wanted folks to get correct information.

If you're like me, your percentage of correct answers will go up in a pretty short time.


------------------
JPD





Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
I'm sure you're right. While Perl is an easy language to learn...There is a learning curve when it comes to understanding how its logic applies to different processes in specific cgi programs.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Thank you Eliot and JPDeni
My old mail address does not work any more. so I registerd new mail address and new name......

I tried this. but it meets error.

I already have ID field in my .cfg file. so I don't need to create it again. right ?
Anyway, $db_key field should be only one in db.
$db_key = 'ID';
$db_key_track = 0;

After I insert the following code, I got error "ID(too long........)
if ($in{'Field 22'} and $in{'Field 23'}) {
$in{'ID'} = $in{'Field 22'} . $in{'Field 23'};

ID field is changed to like below when I try to add new record.
<INPUT TYPE="hidden" NAME="ID" VALUE="Field 22Field 23" SIZE="3" MAXLENGTH="3">
}
Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Change the maxlength in your field definition in the .cfg file to match the maximum total length of the two fields.

For example, if field 22 could have a maximum of 7 characters and field 23 could have a maximum of 10, set the maxlength to 15.

Or you could just set the maximum length to 255. You shouldn't have any problems then.



------------------
JPD





Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
I already set the maximum length to 255 for field 22 and 23.

The problem is that the selected words in field 22 and 23 are printed in ID field.
ID => [0, 'numer', 5, 8, 1, '', ''],
The error massage is ID(too long, max length 8
Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Set the maximum length for the ID field to 255 -- or 510, the length of the other two fields combined.

Your ID field will consist of a combination of field 22 and field 23. The maximum length for the ID field must accommodate the length of the combination. Otherwise you will keep getting the error you're getting.


------------------
JPD





Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Thank you JPDeni

It works.
However, an error occured.

When I modify a record, The ID is not changed according to new selection of field 22 and 23.
So, After modifyingthe record, the ID field and new field 22/23 are different.

How can I solve it ?


[This message has been edited by momo (edited August 12, 1999).]
Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
If you're going to be changing field 22 and 23, I don't think you can do what you want. You cannot change the key field for a record and I don't know of any way to check for a combination of records already existing unless you use the key field.


------------------
JPD





Quote Reply
Re: How can I make no one choose the options it is already taken by former user ? In reply to
Thanks JPD

I understand, how it works.

thanks again.