Using form information for validation

Alex Leverington admin@networkessence.net
Sun, 28 Oct 2001 22:10:26 -0600


---------------------- multipart/mixed attachment

Ok...I'm trying to setup the ticket mdify page in whups so that when you input a
user, there is a drop down menu that lets you select whether you are picking a
username or a user email address. I have _that_ part done. Now, what I'm having
a problem with is that I need the validation of the information to have access
to the value of the usertype selected from the dropdown box.

Search.php:Line 121 (I think, i've changed stuff) says:

$var3 = new Variable('Assignee', 'assignee', getUserType(), true);

This means that the Assignee is verifified via getUserType().

Eventually, that leads to the UserType class defined in Forms.php. The
validation is as below:

    function isValid(&$vars, $value, &$message) {
        $uid = $this->backend->getUserFromEmail($value);

        if (!isset($uid)) {
            $message = "no such user " . htmlspecialchars($value);
            return false;
        }

Which is ok if the person enters an email address. It's not ok if a person
enters a username. So, now I want to change that to something like:

    function isValid(&$vars, $values, &$message) {
        if($values['usertype']=='1')
        $uid = $this->backend->getUserFromEmail($values['input']);
        if($values['usertype']=='2')
        $uid = $this->backend->getUserFromName($values['input']);

        if (!isset($uid)) {
            $message = "no such user " . htmlspecialchars($value);
            return false;
        }

In essence, the problem is that I don't know how to get the $backend (up above)
to use other information from the form for validation. Any ideas?

Attached is a diff of where I'm at.

-Alex

---------------------- multipart/mixed attachment
W3Jvb3QgaG9yZGVdIyBjdnMgLXozIGRpZmYgd2h1cHMNCj8gd2h1cHMvbGliL0JhY2tlbmQvc3Fs
LmJhY2t1cC5waHANCmN2cyBzZXJ2ZXI6IERpZmZpbmcgd2h1cHMNCmN2cyBzZXJ2ZXI6IERpZmZp
bmcgd2h1cHMvY29uZmlnDQpjdnMgc2VydmVyOiBEaWZmaW5nIHdodXBzL2RvY3MNCmN2cyBzZXJ2
ZXI6IERpZmZpbmcgd2h1cHMvZ3JhcGhpY3MNCmN2cyBzZXJ2ZXI6IERpZmZpbmcgd2h1cHMvbGli
DQpJbmRleDogd2h1cHMvbGliL0JhY2tlbmQucGhwDQo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09P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iAgICAgICAg
ICRtb3JlY29tbWVudCA9ICRpbmZvWyduZXdjb21tZW50J107DQogDQotICAgICAgICAkZGV0YWls
cyA9ICR0aGlzLT5nZXRVc2VyRGV0YWlsc0Zyb21FbWFpbCgkZW1haWwpOw0KKyAgICAgICBpZigk
dXNlcnR5cGU9PScxJykNCisgICAgICAgIHsgJGRldGFpbHMgPSAkdGhpcy0+Z2V0VXNlckRldGFp
bHNGcm9tRW1haWwoJGFzc2lnbmVlKTsgfQ0KKyAgICAgICBpZigkdXNlcnR5cGU9PScyJykNCisg
ICAgICAgeyAkZGV0YWlscyA9ICR0aGlzLT5nZXRVc2VyRGVhdGlsc0Zyb21OYW1lKCRhc3NpZ25l
ZSk7IH0NCisNCiAgICAgICAgICRhc3NpZ25lZSA9ICRkZXRhaWxzWydpZCddOw0KICAgICAgICAg
JG5hbWUgPSAkZGV0YWlsc1snbmFtZSddOw0KKyAgICAgICAkZW1haWwgPSAkZGV0YWlsc1snZW1h
aWwnXTsNCiANCiAgICAgICAgICRjb21tZW50ID0gIkFzc2lnbmVkIHRpY2tldCB0byAkbmFtZSA8
JGVtYWlsPiI7DQogDQpAQCAtMjM0LDggKzI0MCw4IEBADQogICAgICAgICB9DQogDQogICAgICAg
ICBpZiAoIWVtcHR5KCRyZXN1bHRbJ3VzZXJfaWRfb3duZXInXSkpIHsNCi0gICAgICAgICAgICAk
cmVzdWx0Wydfb3duZXJfbmFtZSddID0gJHJlc3VsdFsnb3duZXInXTsNCi0gICAgICAgICAgICAk
cmVzdWx0Wydfb3duZXInXSA9ICRyZXN1bHRbJ293bmVyJ107DQorICAgICAgICAgICAgJHJlc3Vs
dFsnX293bmVyX25hbWUnXSA9ICRyZXN1bHRbJ3VzZXJfaWRfb3duZXInXTsNCisgICAgICAgICAg
ICAkcmVzdWx0Wydfb3duZXInXSA9ICRyZXN1bHRbJ3VzZXJfaWRfb3duZXInXTsNCiAgICAgICAg
IH0NCiAgICAgICAgIA0KICAgICAgICAgcmV0dXJuIC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