monetizer expertmobi
Dismiss Notice
Welcome to Our Community
Wanting to join the rest of our members? Feel free to sign up today.

Form validation

Discussion in 'Programming and Scripts' started by Andy Haskins, Oct 21, 2013.

  1. Andy Haskins

    Andy Haskins Affiliate affiliate

    Does anyone know of any quick to implement yet effective form validation? Whether it be PHP or JS.

    For some reason I always seem to choose a different solution when validating my forms but really need to look at streamlining the process...
     
  2. monetizer
  3. valuleadsnick

    valuleadsnick Affiliate Manager Affiliate Manager affiliate

    21
    5
    0
    Andy,

    jQuery is always nice for Form Validations. There are a few out there that you could "Rip" from. I would show you a link but since my post count is only at 7 I cannot. Hopefully when I hit that post count of 10 it will work or just google "jQuery Form Validation" It's great to use jQuery it is user friendly!
     
  4. ljads_jerrold

    ljads_jerrold Affiliate Manager Affiliate Manager affiliate

    105
    61
    28
    I second JQuery and wanna Add in HTML5 into the mix. HTML5 has some built in form validation that may suit what you need. just by adding the 'required' keyword to your input tag will force html5 to notify the user that field is required if they try and submit it.

    Example
    Code:
    <form>
        <input type="text" name="first_name" id="first_name" required>
        <input type="submit" value="submit">
    </form>
    
    if you need regex validation as well you can add another 'pattern' parameter to the input object


    Example (only accepts Letters, Spaces)/B]
    Code:
    <form>
        <input type="text" name="first_name" id="first_name" pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" required>
        <input type="submit" value="submit" >
    </form>
    

    Wow I guess I necro'd the hell outta this post (facepalm)
     
    Last edited: Mar 21, 2014
  5. vnairabhinand

    vnairabhinand Affiliate affiliate

    1
    0
    0
    Yes No need to validate each elements via code as jquery provides a plugin named jquery validate which is effective and will let us do the validation with minimum code and no need to think about the logic of validation at all.

    Andy, the html5 validation is good but if the client side browser is not having that support it may cause db dumping hence the effective method is to use jquery validate and surveys shows that also.

    Thanks
     
    Last edited: May 12, 2014
  6. mlaghfiri

    mlaghfiri Affiliate affiliate

    417
    270
    63
    i am always using Javascript to make it so fast ;)
     
  7. laniii

    laniii Affiliate affiliate

    3
    0
    0
    If your form interracts with database, you NEED to always use backend to validate form.
    Javascript and jQuery is code that anybody can modify while browsing your site, never trust your visitors.

    There is always that one who is looking exploits at your website.

    Javascript is good with pre-validating form but its useless if there is that one guy looking for vulnerabilities.

    I know this is old thread, but hope this post helps those who is thinking this same thing.
     
  8. church

    church Affiliate affiliate

    207
    31
    28
    Andy how important is field validation?
     
  9. ljads_jerrold

    ljads_jerrold Affiliate Manager Affiliate Manager affiliate

    105
    61
    28
    If you are using mysql I sugest looking into using PDO with field tokens.

    Code:
    $query = "SELECT * FROM admin WHERE password='$password';"; 
    
    is just ripe to be taken advantage of with a sql injection. of course you can use mysql_real_escape_string() to help with that however a more elegant solution is the following...

    Code:
    $query = "SELECT * FROM admin WHERE password=:pass";			
    			$stmt = $sql->prepare($query);
    			$stmt->bindParam(':pass', $_POST['password'], PDO::PARAM_STR);						
    			$stmt->execute();
    			$stmt->setFetchMode(PDO::FETCH_ASSOC);
    			$result = $stmt->fetch();
    
    By using PDO you tokenize your variables and the bindParam function sets those variables to the proper TYPE (ie. string) and will escape any weirdness the user tries to send through. Plus this way you are not forgetting to every escape and sanitize any user input which is far more safer then trying to do it yourself.
     

Featured Resources (View All)

MI