check if data already in database

nadjak

Member
Can I check, if some fields (for example name and firstname) already exists in the database?
Thank you
NAdja
 
The 'isuniquevalue' or 'areuniquevalues' validation plugins.

You may have to install them, I can't remember offhand if they are part of the core.

-- hugh
 
Thank you!
It works fine, but can I select more than two elements?
For example I select Name and Firstname. But sometimes this name could have two different persons. So I want another element to compare (for example the birthdate)
Nadja
 
Please, can someone help me with the php validation?
Is this right?
<code>
$app = JFactory::getApplication();
$first = $app->input->get('tablename___firstname', 'default value', 'string');
$last= $app->input->get('tablename___lastname', 'default value', 'string');
$birth= $app->input->get('tablename___birthday', 'default value', 'string');
if($first==$data(firstname) && $last==$data(lastname) && $birth==$data(birthday)) return false;
else return true;
</code>

To explane what I want:
If someone fill in the form it should be checked if the firstname, lastname and birthday already exist.

Is it right to put this code in element - elment_lastname - validation?

Than you
Nadja
 
You'll need to actually search for those values in the database to find out if they already exist.

-- hugh
 
Yes I know.
But something in my code (see last post) is wrong. If I run my form with this validation I get a blanc site.
Is it right, that all form-datas are in $data? Is it right to adress the firstname-field like $data(firstname)?
Thank you for your help
Nadja
 
In validations, all the submitted data from the form is in the $formModel->formData[] array, keyed by full element name. $data only contains the value for the element the validation is on.

-- hugh
 
I changed my code to:
<code>
$app = JFactory::getApplication();
$first = $app->input->get('fab_adresse___FIRSTNAME', 'default value', 'string');
$last= $app->input->get('fab_adresse___NAME', 'default value', 'string');
$birth= $app->input->get('fab_adresse___BIRTHDATE', 'default value', 'string');
if($first==$formModel->formData['fab_adresse___FIRSTNAME'] && $last==$data('fab_adresse___NAME') && $birth==$data('fab_adresse___BIRTHDATE')) return false;
else return true;
</code>
This code is in element - validation - php - php code

But if I send my form I still get a blanc site.
Can someone help me?
Thank you
Nadja
 
There's still numerous issues with that.

First, don't use $app->input->get(), use the $formModel->formData[] array (keyed by the same names.

And as I said, $data isn't an array, it's just the single value of the element the validation is on.

And, even if your code was correct, it would only be comparing the submitted data against itself.

You need to get your three values from the formData, then look those up in the database to see if they exist, but also excluding "this" row if the form is being edited.

This isn't something we can code up for you in Community support.

-- hugh
 
o.k. thank you.
is there a docomentation which can help me with the right php classes and methodes?
Thank you
Nadja
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top