How to hide parts of a page

Discussion in 'PHP' started by lokielookies, Jan 28, 2008.

  1. #1
    In my script, I'm using a php echo statement to 'print' info that was entered in a form on a new page.

    Can someone tell me how I can make sure a certain part of the info on the new page is not visible when the according form field is left blank?

    Example:

    Form:
    <form id="form1" name="form1" method="post" action="result.php">
    My name is<br />
      <label>
      <input type="text" name="textfield" />
      </label>
    <p>Site:</p>
    
      <label>
      <input type="text" name="textfield2" />
      </label>
    
    <p>Extra info:</p>
    
      <label>
      <textarea name="textarea"></textarea>
      </label>
    
    <p>&nbsp; </p>
    
      <label>
      <input type="submit" name="Submit" value="Submit" />
      </label>
    </form>
    PHP:


    Output:

    <p>Hi<em> <?PHP echo $_POST["textfield"];?> 
    </em></p>
    <p>You've registered <em> <?PHP echo $_POST["textfield2"];?>  </em>as your site.</p>
    <p>This is your extra info: <em>  <?PHP echo $_POST["textarea"];?> </em></p>
    <p>&nbsp; </p>
    PHP:
    If the text area next to 'Extra info' is left blank, I want to hide this part on the output screen:

    <p>This is your extra info: <em>  <?PHP echo $_POST["textarea"];?> </em></p>
    <p>&nbsp; </p>
    PHP:
     
    lokielookies, Jan 28, 2008 IP
  2. Possibility

    Possibility Peon

    Messages:
    350
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use conditional statements. Check to make sure that each textarea is not blank, and if not, then output everything. Like so:

    $someText = $_POST['textfield'];
    if($someText != "") { // not empty
    echo "<p>This is your extra info: <em>$someText</em></p><p>&nbsp;</p>";
    }
    PHP:
    That way it would only print all of that if there was some value inside of $_POST['textfield']
     
    Possibility, Jan 28, 2008 IP