This topic is locked

Validate Field on Add, Edit

8/25/2009 11:55:16 AM
PHPRunner General questions
J
jvoirol author

Hello,
I am using PHPRunner 5.1 (Build 2503)
I would like to validate a field dependent on the value in another field. I have a timesheet application where the user can choose from a list of time types, i.e. labor, weekend, vacation, holiday, sick, etc. If the user chooses weekend then I want the hours field to be 0. I think I put this in the event, before record added, and return false if the above is true otherwise return true. I think the logic is like this:
if $values["type"]="weekend" and $values["hours"]>0

$message "if type is weekend then hours must be 0"

return false

else

return true;
Thanks

J
jvoirol author 8/25/2009



Hello,
I am using PHPRunner 5.1 (Build 2503)
I would like to validate a field dependent on the value in another field. I have a timesheet application where the user can choose from a list of time types, i.e. labor, weekend, vacation, holiday, sick, etc. If the user chooses weekend then I want the hours field to be 0. I think I put this in the event, before record added, and return false if the above is true otherwise return true. I think the logic is like this:
if $values["type"]="weekend" and $values["hours"]>0

$message "if type is weekend then hours must be 0"

return false

else

return true;
Thanks


I got it working, here is the code. Stupid parentheses!
if (($values["type"])=="Weekend" && ($values["hours"])>0)

{

echo "ERROR! Hours for this time type cannot be greater than 0";

return false;

}

else

if (($values["type"])=="Non-Working" && ($values["hours"])>0)

{

echo "ERROR! Hours for this time type cannot be greater than 0";

return false;

}

else

if (($values["type"])=="Standby" && ($values["hours"])<=0)

{

echo "ERROR! Hours for this time type must be greater than 0";

return false;

}

else

if (($values["type"])=="Labor" && ($values["hours"])<=0)

{

echo "ERROR! Hours for this time type must be greater than 0";

return false;

}

else

return true;