SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form field validation

    Hello good pple of the forum,
    I am validating my form fields using php, ok letís say there is no text in the firstname text field, but there is text in the lastname field, when I hit the submit button, the validation text echos out that the firstname text field is empty and then displays the again (which is index.php). But the is my previous text in the lastname text field disappears. Pls how can I overcome this?
    Thank you.
    PHP Code:
    if((!$first)||(!$last)||(!$email)||(!$edu)||($_FILES['resume']['type']!='application/msword'))
             {
             echo 
    'you did not submit the following info<br/>';
             if(!
    $first)
             {
             echo 
    'first name is a required field<br/>';
             }
             if(!
    $last)
             {
             echo 
    'last name is a required field<br/>';
             }
             if(!
    $email)
             {
             echo 
    'email is a required field<br/>';
             }
             if(!
    $edu)
             {
             echo 
    'highest qualificaiton is a required field<br/>';
             }
             if(
    $_FILES['resume']['type']!='application/msword')
             {
             echo 
    ' make sure the file type is a Microsoft Word document<br/>';
             }
             include 
    'index.php';
             exit();
             } 

  2. #2
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of reloading the page, output the code error and provide a back button and the data should be there.

    Keith

  3. #3
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use something like this
    PHP Code:
    <?php
    $fname
    ="";
    $lname="";
    $error="";
    if(isset(
    $_POST['submit'])){
    //Check if data field is empty
        
    $fname=$_POST['fname']; 
        
    $lname=$_POST['lname']; 
        if(!
    $fname || !$lname$error="Empty Data fieldS ";
        else{
            
    // insert data into db
        
    }
    }
    if(
    $error || !isset($_POST['submit'])){
    echo 
    $error;

    ?>
    <table border="0"><form action="" method="post"> 
    <tr align="left"><td>First Name</td>
    <td><input name="fname" type="text" size="40" value="<?php echo $fname?>"></td></tr>
    <tr align="left"><td>Last Name</td>
    <td><input name="lname" type="text" size="40" value="<?php echo $lname?>"></td></tr>
    <tr><td colspan="2" align="center">
    <input name="create" type="submit" value="Enter">
    <INPUT class=button accessKey=r tabIndex=1 type=reset value="Reset Fields"></td></tr>
    </form></table>
    <?php
    }
    ?>
    And this shud b on the same page
    Last edited by lmasi02; Jan 3, 2006 at 08:30.
    Power of Knowledge


Bookmarks

Posting Permissions

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