How to skip a blank field in a form when posted

Discussion in 'PHP' started by bbw82, Dec 1, 2011.

  1. #1
    I have a basicc form that takes users info and when they submit it it show on a new web page in the proper order. I need to know how do I skip a blank field. This form takes a users First, Middle, and Last name but many times they leave the middle name blank so I would want to skip this field from showing up when the form is posted. Here is what I have for the basic php script ..Would like to know how to skip a field if it is left blank on the form.

    echo $_POST["First"], print "."; ?><?php echo $_POST["Middle"], print "."; ?><?php echo $_POST["Last"], print "."; ?><?php echo $_POST["Persona1"], print ".";<br />
     
    Last edited: Dec 1, 2011
    bbw82, Dec 1, 2011 IP
  2. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #2
    Using your output formatting...

    <?php
    
    echo $_POST['First'];
    echo '.';
    if((isset($_POST['Middle'])) && (strlen(trim($_POST['Middle']))))
    {
        echo $_POST['Middle'];
        echo '.';
    }
    echo $_POST['Last'];
    echo '.';
    
    ?>
    PHP:
     
    mfscripts, Dec 2, 2011 IP