I am trying to work out what would be the fastest way to compare user data which has been entered into a form with user data that is already stored in the database.

My plan was to pull all details of a single column into an array i.e. email, then compare them with the value entered, but I think that will get vary slow as the database grows.

My second idea was to use Zend_validate::is($email,'email') but that throws the error 'Validate class not found from basename'. The only information I can find on this error is references to a bug.

My question is: When comparing value from a form and database what would produce the quickest results?


This is part of a custom module (my first one)

I am trying to avoid duplications within my table

The module will provide me with a list of people who are not members but want information specific events

  • That method will try to validate that the input is an email. Are you trying to prevent duplicates in the DB? Magento prevents duplicate emails for customers - are you modifying/extending something? – Jongosi Jul 26 '13 at 11:32
  • 2
    Are you intending to validate client-side? What problem are you trying to solve (e.g. "account already exists")? – benmarks Jul 26 '13 at 11:43
  • Please see my edit and I would like to validate, both client and server side – tony09uk Jul 26 '13 at 12:13

You could do one of a few things here. These are the two I would suggest, but that is mainly personal opinion.

  1. Validate before you save the object - have a look at how the customer object works, basically it has a validate function that does some checks and if any throws an error then it adds them to an error array. Then simply call this before you save your model and only save when the error array is empty,
  2. Ajax validation - you could add a ajax call before you submit your form, either on blur of the field or simply before the form is submitted, then what you can do is call some controller somewhere that checks to see if their is already an entity saved with this information. If there is then show the error, otherwise submit the form as normal,
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.