![]() |
Sergey Kornilov admin 12/9/2006 |
Shawn, function BeforeAdd(&$values) { // Parameters: // $values - Array object. // Each field on the Add form represented as 'Field name'-'Field value' pair //** Check if specific record exists **** global $conn; *$strSQLExists = "select from ParentTable where ID=" . $values["ParentID"];** $rsExists = db_query($strSQLExists,$conn); $data=db_fetch_array($rsExists); if($data) { // if record exists do something return true; } else { // if dont exist do something else return false; } // return true if you like to proceed with adding new record // return false in other case } |
L
|
larsonsc author 12/9/2006 |
So all I need to do is edit the "ParentTable", "ID", and "ParentID" values to the proper table/field names? I do not need to code anything in the if/else section? |
L
|
larsonsc author 12/10/2006 |
OK, I figured out how to prevent the record from being added using the BeforeRecordAdd event. However, I would like when the page is redrawn, for an error to print on the screen stating that the ID # was invalid, which I can do with an echo statement. But is there any way for me to control where it appears on the page in the event code? I would like to have the error message print out right about where it would normally say "<<<Record Added>>>" rather than above the header file. |
L
|
larsonsc author 12/11/2006 |
OK, I have another question related to the code for BeforeAdd functions. I am trying to do multiple verifications against data before a record gets added to make sure certain data is valid when the record is inserted. However, it seems that my general lack of knowledge in coding functions is causing everything to get inserted no matter what the data is so long as it is a valid type.
function BeforeAdd(&$values) |
L
|
larsonsc author 12/11/2006 |
Nevermind...I stared at this a bit longer and realized the error of my ways. All I had to do to make it work was call the array value for Date_Of_Birth that I already had in $data and use the right date function. I was overcomplicating things as usual by calling a second query to get a values I already had. |
L
|
larsonsc author 12/12/2006 |
I managed to get my data validity checks working and I thought I would share the solution here in case anyone else ever found a need to do the same kind of check. This code is a BeforeAdd function and performs the following checks:
This could of course be adapted to other checks, but if anyone needs to comapre dates for reasons like I listed above, or for any other reason, you could just modify the code to reflect your own comparisons. Hope this can help someone. <?php |