This topic is locked

Check field before insert?

1/4/2009 11:57:13 PM
PHPRunner General questions
R
run4sbc author

I was wondering if anyone had found a way to check the contents of a field before its saved/updated to the database.
I had found some ideas to do it in javascript but it wont work well with the code from PHPRunner...
Basically what i wanna do is check a field based on another field, for example, if field A is TJ, i want field B to be in the format 34.45 (two numbers, decimal, two numbers) and say field A is 3000, make field B be in the format of 8:34.45 (number, colon, 2 numbers, decimal, two numbers)
Thanks for any help you have!

Cody

J
Jane 1/5/2009

Hi,
use Before record added/Before record updatedevents on the Events tab.

All entered values are stored in the $values array.

R
run4sbc author 1/5/2009

Jane, I kinda figured that...but I didn't know how you would actually check it vs the data entered...I was kinda hoping someone had already done something similar so I had an example to work off of. I'm not the best event scripter, but I can work my way through it is someone gives me an example to work off of. But as always, thanks for you help!

J
Jane 1/6/2009

Hi,
here is just a sample:

if ($values["A"]=="TJ")

{

if (preg_match("/[0-9]{2}\.[0-9]{2}/", $values["B"], $matches) && strlen($values["B"])==5)

return true;

else

return false;

}



More info here:

http://www.webcheatsheet.com/php/regular_expressions.php

R
run4sbc author 1/6/2009

Looks great, I'm going to plug it in tonight and give it a try....thank you so much Jane!!
Cody