Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: checking fields

  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    checking fields

    Hi

    I have a form that the user fills in details.
    I want to make sure only numbers are in certain fields and letters in others.
    I also want to make sure all fields are filled in before a user can continue.

    What's the best way of alerting a user?
    Are message boxes a good idea and how can these be done in php?

    thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Message boxes are not nearly as good as imbedding attractive "hints" for the user to please enter the right info. You can do this easily by imbedding PHP echo statements on the return trip from a form submit.

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There are many ways to do it.
    if u want to do it with some javascript.then good.
    I am not talking about to use java for validation just for popup error,
    Bcoz when a user submits a form the fields will varified by the php validation
    code ,if filed empty or letter or numbers problem, that popup msg comeout and when a user click ok, page will goback to previous page asking user to fill
    in.(Note:this is automatically when user click on popup ok button).
    Other u can use echo but for that the user will hit back button of the
    browser to go back.(i think this is not better way to do this.).

    I have some validation code in php and error msg with popup.
    If required i will post for u.

  • #4
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    R u read my above post.

  • #5
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i would really appreciate if you could post the validation code for me.Thank you

  • #6
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This code is for letters:
    PHP Code:
    if ( !preg_match('/^[a-zA-Z\" "]*$/'$name) ) 
       {      
        
    error('Name is not Valid.\\n'.
                
    'Please try again.');
          } 
    This is for the numbers:
    PHP Code:
    if ( !preg_match('/^[0-9\" "]*$/'$cleaned_for_sql['hp']) ) 
       {      
        
    error ('HP Number is not Valid.\\n'.
        
    'Please try again.');
          } 
    Now save the following script as validate.php and include it as
    PHP Code:
     include('include/validate.php'); 
    Code:
    PHP Code:
    <?php 
    function error($msg) {    
        
    ?>    
          <script language="JavaScript">     
          <!--
           alert("<?php echo ($msg?> ");
            history.back();
       -->
        </script>        
        <?php
        
    exit;
    }
    ?>
    I think this will help.

  • #7
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks that's great!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •