Gossamer Forum
Home : Products : DBMan : Customization :

Dependant fields problem

Quote Reply
Dependant fields problem
Good day ~ this may be easy, but not to me right now !

I want to test an expression, in add or modify. If the expression is not blank, then another field equals x.

in sub
html_record_form

if ($rec{'Orderedby'} ne '') {

print qq|<INPUT TYPE=
"HIDDEN" NAME="Status" VALUE="Ordered" SIZE="12" MAXLENGTH="12"></td> |;

}

else {

print qq|<INPUT TYPE="HIDDEN" NAME="Status" VALUE="Pending" SIZE="12" MAXLENGTH="12"></td> |; }

or similiar syntax ~ ANYway when i am adding the record, the field 'Orderedby' is blank.... thus, if a user fills it in, the file is saved and the expression is not really tested until the file is modified, at which point the test sees a value in 'Orderedby' and makes the change in the other field.

So, I add a record, the 'orderedby' is blank. then, modify it, fill in 'Orderedby' but there is no value seen until the record is written, so 'Status' stays the same... modify the record again, and the value is changed. Some days I hate perl. This was going along swimmingly until this little glitch ! thank you !
Quote Reply
Re: [sonofschwa] Dependant fields problem In reply to
Yep... perl is a "cause and effect" type of thing. If you want to do it before the page is "rendered" then you'd have come up with something else. Frown

I use javascript on some of my forms to handle things dynamically (check out http://javascript.internet.com) but anything that is 'really cool' is usually limited to Internet Explorer version 6+. So if you go that route you'd potentially be limiting your audience/users.

Good luck, and perhaps others will throw in some suggestions as well.
Quote Reply
Re: [Watts] Dependant fields problem In reply to
Yup ~ no way around it other than posting the form twice. So i will try out javascript ~ hopefully today ~ and let you know how it goes

Thank you for the response !
Quote Reply
Re: [sonofschwa] Dependant fields problem In reply to
As you can tell by my "novice" status I am not a PERL guru. However, you may be able to do this in db.cgi, not the input form.

Stop me if I am wrong Real PERL guru's, but in db.cgi's sub add_record you could put the logic and calculation you need.

if ($in{'FieldX'} ne '') {

$in{'FieldY'} = "Ordered"

}

elsif {
$in{'FieldY'} = "Pending"

}

Or something like it, my PERL grammar or my typing is probably a little off and you may need to do some other code to make it perfect.

This would also let you keep the field you want hidden off the form completely, if that is a concern.

I have done this to calculate unique keys in related databases. The basic logic comes from JPDeni and her many mods; you may want to search for some of her posts to see what she has had to say.