This topic is locked

Before Edit event 'updates' when function returns false

7/27/2006 8:05:04 PM
PHPRunner General questions
G
gawde author

Hello all.
I have a similar problem to "Field Validation - Required Fields" posted by warrenk on July 16, 2006.
Specifically, I have duplicate checking code in the Before Edit event that sets Return False when the key field is changed to a value already in the table. (the key field value is user originated) I issue a tiny Javascript message informing the user of the error. The edit form does NOT perform the update but the << Record Updated >> message appears. Not a huge issue but will probably confuse the users a "bit" (as it did me during testing).
Anyone run into this? Do I have to set something else to supress the "Updated" message?
Any thoughts on this will help.

Alexey admin 7/28/2006

Hi,
make sure you have this line in your BeforeEdit event handler

BeforeEdit = False


Also you can post the code of your event handler here and I'll tell you what to fix in it.

G
gawde author 7/28/2006

Hi,

make sure you have this line in your BeforeEdit event handler
Also you can post the code of your event handler here and I'll tell you what to fix in it.


Sorry Alexey, but I just couldn't get this simple one liner to work. I kept getting PHP syntax errors no matter what combination of quotes and/or $'s I tried. I must be missing something. So.... here's the entire event code I'm using including your one line suggestion.
Thanks much. Greg.
//** Check if specific record exists ****

global $conn;

$oldkey = "'".$_REQUEST["editid"]."'";

if ($oldkey !== $values["UserID"])

{

$tempvalue = str_replace("'", "", $values["UserID"]);

$strSQLExists = "select * from _UserSecurity where UserID = ".$values["UserID"];

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data)

{

// if record exists do something

echo "<script> alert('User ID ".$tempvalue." already exists.'); </script>";
BeforeEdit = False;

return false;

}

else

{

// if dont exist do something else

}

}

return true;

Alexey admin 7/31/2006

Hi,
I'm sorry, you don't need

BeforeEdit = False



line at all.

Just remove it.
To suppress the "Record updated" message modify ..._edit.php file.

Replace this snippet:

// after add event

if(function_exists("AfterEdit"))

AfterEdit();

}

$message="<div class=message><<< ".##SCRIPTMESSAGE(RECORD_UPDATED)##." >>></div>";

}



with the following:

// after add event

if(function_exists("AfterEdit"))

AfterEdit();

$message="<div class=message><<< ".##SCRIPTMESSAGE(RECORD_UPDATED)##." >>></div>";

}

}

G
gawde author 7/31/2006

Thanks much Alexey. The last suggestion did the trick.
Love the product and the support.
greg