You are not logged in.
Hi, I am new to this framework and I've taken over working on an existing site for a client. They have a public_users table and module set up. There is a public-user extension setup with a "classes/" directory and a PublicUser class that extends BigTreeModuledefined.
When a new user is added, we need to ensure that there is not already an existing user with the same email address. I'm having trouble figuring where to implement this validation, either in the backend, or if possible, frontend.
Any help would be greatly appreciated.
Thanks!
Daniel
Offline
Hi Daniel!
In the front-end of your website you have full control over how the data gets into the database. The easiest way to check if a user exists in your table before inserting it would be to make an instance of your module's class and use getMatching. e.g.
$mod = new PublicUsers;
if (count($mod->getMatching("email", $_POST["email"])) {
// user exists
} else {
// insert user
}
On the back-end, you could do this through a custom field type. You could throw an error in your custom field's process file if there's already a matching email in the database table.
Offline
Thank you so much for aiming me in a good direction. I will explore both of these approaches and see which works best. If I get stumped I will post a follow-up in this thread, in case anyone else could benefit from it.
Thanks again!
Offline
I got this working by creating a custom field type and made it add an error to $bigtree["errors"] when the email already exists. The only problem now is that it throws the error when updating the record. How can I make it only test the condition only when a new record is being added?
Thanks a million!
Offline
You can check for whether you're updating an existing entry by doing:
if (!empty($bigtree["existing_data"]["id"])) {
// Updating something that already exists
}
Offline