Is there a way to do this in PHP

Discussion in 'PHP' started by oo7ml, Oct 26, 2007.

  1. #1
    I have JavaScript validation on my form that checks to see that the default value in the message field is not being submitted, however i want to add the same validation in PHP

    Here is my JavaScript validation

    if ((numofchar<1) || (numofchar>500) || value.indexOf('(Please fill in this field)')!=-1)
    HTML:
    so this makes sure that the user cannot enter "Please fill in this field" in the message field

    AND

    they cannot enter "Please fill in this field asasdad" in the message field


    I want the add the same validation in PHP

    Here is what i currently have in my PHP validation:

    if ((strlen( $about_me) < 1	|| strlen( $about_me) > 500 ))
    PHP:

    Can someone please help me add a PHP version of the JavaScript validation above so that it checks to see if the string "Please fill in this field" is in the string trying to be submitted, thanks
     
    oo7ml, Oct 26, 2007 IP
  2. jmhyer123

    jmhyer123 Peon

    Messages:
    542
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you would just add the following code:

    
    preg_match("Please fill in this field", $about_me);
    
    Code (markup):
    so your code would look like this:

    
    $text = "Please fill in this field";
    
    if ((strlen( $about_me) < 1 || strlen( $about_me) > 500 ) && preg_match($text, $about_me))
    
    Code (markup):
    That will make it fail if it finds $text or "Please fill in this field", otherwise it will continue on.
     
    jmhyer123, Oct 26, 2007 IP
  3. grikis

    grikis Banned

    Messages:
    333
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    if (strlen($about_me) < 1 OR strlen($about_me) > 500){echo "Please fill in this field!"; die;}
     
    grikis, Oct 26, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    the literal translation of that line is

    
    if(  ( strlen( $string ) < 1 || strlen( $string ) > 500 ) || strpos( $string, '(Please fill in this field)' ) !== false )
    
    PHP:
     
    krakjoe, Oct 27, 2007 IP
  5. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #5
    
    if ((strlen( $about_me) < 1) || (strlen($about_me) > 500) || !strcmp($about_me,"Please fill in this field")) {
    //code
    }
    
    PHP:
     
    legend2, Oct 27, 2007 IP