News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

Check if email exists?

Started by MrLeN, August 11, 2012, 10:51:36 AM

Previous topic - Next topic

MrLeN

I would like an existing form that I have on my website to check the SMF database to see if an email exists.

Something like:


#connect to database (how?)
$email = [email protected]
if (exists($email)) {
  #error message, can't continue
}


Can anyone help me fill in the blanks?

The purpose is that if someone is already registered on my forums with an email, I don't want them to be able to fill out the particular form (with that email).

edit: My forum is 2.0.2

CapadY

This is an default function from SMF forums.

You can never register twice with the same email address.
Just try it yourself :)
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

MrLeN

What I am requesting is for an existing form (not for SMF registration). I am aware that you cannot join with an existing email (which is why I want to check the SMF database for that email). The form I am working on is a separate form from SMF. I don't want the people to people able to submit the form (which is on a completely different part of the website) if they are registered on the forum. I hope that clears things up.

Kays

H, if you include SSI.php then you can use the profileValidateEmail() function. Profile-Modify.php will need to be included also.

http://support.simplemachines.org/function_db/index.php?action=view_function;id=820

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

MrLeN

Quote from: Kays on August 13, 2012, 07:39:26 AM
H, if you include SSI.php then you can use the profileValidateEmail() function. Profile-Modify.php will need to be included also.

http://support.simplemachines.org/function_db/index.php?action=view_function;id=820

That would require the user to be logged in to the forum. My form just needs to know if the email is in the smf database (whether they're logged in or not).

Kays

Hmm, i've got to admit that I've never used it. But if that is the case, just use the code from it to do your own  check

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

emanuele

Nope, Kays is right.

profileValidateEmail returns true if the email is not used by any member, otherwise it returns an error code (that is the index of an error string that you can use to display warning.

For example:
<?php
require_once('/path/to/SSI.php');
global
$sourcedir;
require_once(
$sourcedir . '/Profile-Modify.php');

$email = isset($_POST['email']) ? $_POST['email'] : '';
$valid_email = profileValidateEmail($email);

if (
$valid_email !== true)
{
   
loadLanguage('Errors');
   
fatal_lang_error('profile_error_' . $valid_email, false);
}

that should do what you need.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

MrLeN

Quote from: emanuele on August 13, 2012, 10:04:44 AM
Nope, Kays is right.

profileValidateEmail returns true if the email is not used by any member, otherwise it returns an error code (that is the index of an error string that you can use to display warning.

For example:
<?php
require_once('/path/to/SSI.php');
global
$sourcedir;
require_once(
$sourcedir . '/Profile-Modify.php');

$email = isset($_POST['email']) ? $_POST['email'] : '';
$valid_email = profileValidateEmail($email);

if (
$valid_email !== true)
{
   
loadLanguage('Errors');
   
fatal_lang_error('profile_error_' . $valid_email, false);
}

that should do what you need.

okies, thanks. That makes mores sense now :)

I can see how that could work. I can't edit the site right now, but I will try it later. I'll let you know how it went.


And thanks Kays -- sorry. I just didn't understand your first response. Programming isn't my forte, and there were too many blanks not filled in (that I didn't have the knowledge to read between the liens for), so I just didn't get it. But by looking at the example above, I get it now. I think that will work.

Advertisement: