how to check

Discussion in 'PHP' started by hulkrana, Apr 25, 2007.

  1. #1
    hello frds

    how we can check that our field textvalues are empty or not?
    thanks and regards
     
    hulkrana, Apr 25, 2007 IP
  2. seoeye

    seoeye Banned

    Messages:
    85
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    u can use javascripts to check it.
    <script language="JavaScript" type="text/javascript">

    function check( form )
    {

    if (form.email.value == "") {
    alert( "Please enter your email address." );
    form.email.focus();
    return false ;
    }

    }

    </script>

    this scripts will work fine.
     
    seoeye, Apr 25, 2007 IP
  3. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #3
    
    if ( empty( $_GET['field'] ) )
        echo 'This field is empty!';
    
    PHP:
     
    Nikolas, Apr 25, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    EDIT: A few seconds too late...

    Don't use JavaScript to validate the user input. It's not secure at all.

    
    
    if (trim($_POST['foo']) == '')
    {
        echo 'Please fill out all required fields.';
    }
    
    
    PHP:
     
    nico_swd, Apr 25, 2007 IP
  5. seoeye

    seoeye Banned

    Messages:
    85
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    how javascripts is not secure? can u explain me?
     
    seoeye, Apr 25, 2007 IP
  6. ottodo

    ottodo Guest

    Messages:
    2,055
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    0
    #6
    well some times its usefull to check on the client side before the server :)
     
    ottodo, Apr 25, 2007 IP
  7. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #7

    He mean by this , user can disable javascript ...

    The best would be to :

    - test user side then test server side
     
    commandos, Apr 25, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    Yes, as additional check. But I often find it a waste of time when you have to code the PHP check anyway. In some cases it can be useful indeed, to prevent users fro having to use the back button, etc...
     
    nico_swd, Apr 25, 2007 IP