How to validate form using array instead of if/else statments

Discussion in 'PHP' started by eritrea1, Nov 25, 2012.

  1. #1
    Hi, I saw somewhere I can't remember a use validating a registration form using array[], errors .. something like that but did not use if/else statements. The errors were constructed in arrays. Anyway, what is a neat way validating inputs?

    thanks
     
    eritrea1, Nov 25, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    You can build yourselve a function that does all the work for you, as i have done many times! and insert it with a to check array with variables.

    In my case the array looked something like this.

    
    $a = array('fieldtocheck' => array('min' => 10, 'max' => 100,
    'type' => 'numeric'),
                   'fieldtocheck1' => array('type' => 'email'),
                   'fieldtocheck2' => array('type' => 'regex', 'value' => 'regexstring'));
    
    Code (markup):
    etc :)
     
    EricBruggema, Nov 25, 2012 IP
  3. downloadphpscripts

    downloadphpscripts Peon

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #3
    downloadphpscripts, Nov 26, 2012 IP
  4. davetrebas

    davetrebas Active Member

    Messages:
    301
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    78
    #4
    You might think about using AJAX for forms validation. Do a Google search on "php ajax form validation" for more info. A little more to it, but a better user experience.
     
    davetrebas, Nov 27, 2012 IP