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 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    valid different form fields

    greeting to all

    i got a simple form which has 4 input boxes, and all need to be valided before submit. the Name box "not empty", the Phonenumber box "digits only", the email box "valid email format" and the Confirm email box "just make sure email address matching".

    the code i'm using now can do the first three jobs, but the matching function not too good. the problems i'm having now is:

    1. the exclamtion mark already there when first load the form.
    2. confirm email only works when one of the Email box and Confirm Email box is empty and the other one IS NOT(i wrote the matching code myself, so not surprised ).

    here's the code

    Code:
    <?php
    // Create an empty array to hold the error messages.
    $arrErrors = array();
    if (!empty($_POST['submit'])) {
        // Each time there's an error, add an error message to the error array
        // using the field name as the key.
    if ($_POST['name']=='')
            $arrErrors['name'] = 'Please enter your name.';
    if (!preg_match("/^[0-9\. ]+$/",$_POST['phonenumber']))
           $arrErrors['phonenumber'] = 'digits only! ';
    if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email']))
           $arrErrors['email'] = 'Email address not valid!'; 
    if (!$_POST['confirm']==$_POST['email'])
    	$arrErrors['confirm'] = 'Email address not matching!';
    }
    ?>
    
    <form method="post" action="<?php echo $PHP_SELF; ?>">
    
    <?php if (!empty($arrErrors['name'])) ?>
    <label for="title">Name</label>
    <input type="text" name="name" value="<?php echo $_POST['name'] ?>">
    <?php if (!empty($arrErrors['name'])) echo '<font color="red">!</font>'.$arrErrors['name'] ; ?>
    <br>
    
    
    <?php if (!preg_match("/^[0-9\. ]+$/",$_POST['phonenumber'])) ?>
    <label for="phonenumber">Phonenumber</label>
    <input type="text" name="phonenumber" class"textfield" maxlength=5 value="<?php echo $_POST['phonenumber'] ?>">
    <?php if (!preg_match("/^[0-9\. ]+$/",$_POST['phonenumber'])) echo '<font color="red">!</font>'.$arrErrors['phonenumber'] ; ?>
    <br>
    
    
    
    <?php if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) ?>
    <label for="email">Email</label>
    <input type="text" name="email" class"textfield" size="30" maxlength=40 value="<?php echo $_POST['email'] ?>">
    <?php if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) echo '<font color="red">!</font>'.$arrErrors['email'] ; ?>
    <br>
    
    <?php if (!$_POST['confirm']==$_POST['email']) ?>
    <label for="confirm">Confirm Email</label>
    <input type="text" name="confirm" class"textfield" size="30" maxlength=40 value="<?php echo $_POST['confirm'] ?>">
    <?php if (!$_POST['confirm']==$_POST['email']) echo '<font color="red">!</font>'.$arrErrors['confirm'] ; ?>
    <br>
    
    
    <p>
    &nbsp;
    </p>
    
    <div id="button">
    <input name="submit" type="submit" class="submit" value="Submit" />
    </div>
    
    </form>

    so, what's the problem? shall i use isDifferent function for the matching?(not try yet).
    one more thing, the action direct the page back to itself, so how can i carry on insert the data into database when pass the validation?

    appreciate any reply!

  • #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
    Try

    Code:
    if ($_POST['confirm'] != $_POST['email'])

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thx Fumigator, that part works beautifully now!
    any idea about other problems?

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hello, can i just ask, which part of the code makes sure that the e-mail ad entered is valid e-mail format?

    thanks!

  • #5
    Regular Coder
    Join Date
    May 2006
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and where do i insert it in the code? thanks again!
    Last edited by belledumonde; 07-27-2006 at 01:43 PM.


  •  

    Posting Permissions

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