SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist JordashTalon's Avatar
    Join Date
    Dec 2008
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Validation PHP, any shortcuts for this?

    Ok to validate one of my forms I do the following

    Code:
    if($var && $othervar && $anothervar){
    echo "form completed";
    }
    else{
    echo "form not completed";
    }
    I want to know which variable did not have the value so I can tell that to the person, how can I do that without doing an if statement for each variable

    e.g.

    if(!$var){
    echo "you missed the ".$var." field";
    }

    Is there a faster way than that?

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using an array to store possibly errors and echo it near the form.

  3. #3
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JordashTalon View Post
    Is there a faster way than that?
    Yes, use or design a form object.

    Here's a post I made showing a simple form/validation class:

    http://www.sitepoint.com/forums/showpost.php?p=4094642
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  4. #4
    SitePoint Evangelist JordashTalon's Avatar
    Join Date
    Dec 2008
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bhanson View Post
    Yes, use or design a form object.

    Here's a post I made showing a simple form/validation class:

    http://www.sitepoint.com/forums/showpost.php?p=4094642
    Looks pretty good, i'll try and use it in my next Form, Thanks


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
  •