SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validating with OOPs

    Hello Guys,

    I am having a registartion form.When the user fills the information ,I want to validate the user data(username,password,first name,last name,email,zip, phone,etc) using oops.

    Can anyone help me with right direction?
    Thanks in adv
    Barbara

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Do you have experience with OOP PHP before?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And what have you tried so far?

  4. #4
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys,

    I know the OOPs concept.But not implemented before.
    I have a class for user,and one method addNewUser() which I want to use for inserting data to table.Before inserting the data I want to validate.
    So, I don't know how to define the function.

    Please give me right direction.
    Barbara

  5. #5
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by barbara1712
    I know the OOPs concept.But not implemented before.
    implement it.

  6. #6

  7. #7
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For input validation, I would write a class that can accept a set of rules for each form field that needs validation, say though an addRule() method. You could store rules for various forms in a database and let database data configure the class for use with a specific form.

    The rules could be assigned to specific input values or groups of values. You could have a rule for valid email or one to just indicate that the a text field was filled out. If you had a requirement that at least one of a group of checkboxes be checked with a "yes" answer on a form then you could have a rule that would evaluate that at least one of a specific group of input values be a particular string value, in this case "yes". You should be able to apply multiple rules to the same input value.

    There are all kinds of potential validation rules and filters you could implement. Make sure the class can keep track of which elements caused an error and provide a quick way to determine that the submission as a whole is valid, or that there was an error.

    Write it to be as generic as possible, and it could be used in any project.

    I have one each of these in Javascript and PHP. They save a lot of time.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •