Aaron
Posts: 145
|
| Posted: 07/06/2007, 6:32 AM |
|
I know there has to be an easy way to do this and I'm just not seeing it.
I have a form that inserts its contents into many tables of a database. In this instance, we are gathering a person's information and putting their phone numbers into a phone number table, address in address table, etc., etc. Well, if, say a phone number has not been entered for a work phone and that field of the form is blank, I don't want to run the insert because I don't want an incomplete record entered. Right now the insert for the form is in an Event; AfterExecuteInsert
I was thinking an IF statement would work but it's getting beyond complicated or I'm just missing something with building it properly. Checking the field properties I looked at the Client > On Change event but I don't think that's what I'm looking for.
Basically the IF would be ... if form field has data, run insert. else, continue.
Any suggestions?
|
Aaron
Posts: 145
|
| Posted: 07/06/2007, 8:03 AM |
|
And low & behold, you give a monkey enough coffee, he too can figure out his variables aren't spelled correctly from code to database. Oy...
If anyone finds this while searching for something, the code I used (and am open to the public ridicule of poorly written code) is as follows, placed in the AfterExecuteInsert of the record form:
// INSERT INTO URI (POAPTID, URISchemeID, URIContextID, uriDescr, startingDate, endingDate, UserID)
// VALUES ($last_POAPT_id, 1(phone), 2(home), data_from_field, CURDATE, 3000-12-31, currentUser);
if(CCStrlen($Person->phoneHome->GetValue())){
$SQL = "INSERT INTO URI (POAPTID, URISchemeID, URIContextID, uriDescr, startingDate, endingDate, UserID) ".
"VALUES(".$db->ToSQL($last_POAPT_id,ccsInteger).", ".
"'1',".
"'2',".
$db->ToSQL($Person->phoneHome->GetValue(),ccsText).", '".
date('Y-m-d')."',".
"'3000-12-31'".",".
$db->ToSQL($Person->UserID->GetValue(),ccsInteger).")";
$db->query($SQL);
}
// End INSERT URI
There are multiples of this that run through Home Phone, Work Phone, Work FAX, Home FAX, email, etc., etc. Any thoughts on creating just *one* statement instead of one for each field, I'm open to the suggestion.
Aaron
|