Page 1 of 1

if then state with echo

Posted: Mon Nov 03, 2008 5:47 pm
by tonyledenko
Hello,

Below is a form redirect page. When the form is filled out the following will be seen on the redirect page. What I would like to do is hide the echos that aren't filled out.

So, for instance, if the name and company are filled out then I would like the redirect page to look like this:

Name: What ever is typed in
Company: What ever is typed in


Then I would like the other fields to be hidden.

Currently if the name and company are filled in then it looks like this:

Name: What ever is type in
Company: What ever is typed in
Phone:
Email:
Address:
City:
State:


<span class="content"><strong>Name:</strong></span> <span class="contentred"><?php echo $fullname; ?></span><br>
<span class="content"><strong>Company:</strong></span> <span class="contentred"><?php echo $company; ?></span><br>
<span class="content"><strong>Phone:</strong></span> <span class="contentred"><?php echo $phone; ?></span><br>
<span class="content"><strong>Email:</strong></span> <span class="contentred"><?php echo $email; ?></span><br>
<span class="content"><strong>Address:</strong></span> <span class="contentred"><?php echo $address; ?></span><br>
<span class="content"><strong>City:</strong></span> <span class="contentred"><?php echo $city; ?></span><br>
<span class="content"><strong>State:</strong></span> <span class="contentred"><?php echo $state; ?></span><br>

Re: if then state with echo

Posted: Mon Nov 03, 2008 6:30 pm
by requinix
The if construct can be really helpful if you know what it is. Consider using it to print something only if a condition is true.

Code: Select all

<?php if ($fullname) echo '<span class="content"><strong>Name:</strong></span> <span class="contentred">', $fullname, '</span><br>'; ?>

Re: if then state with echo

Posted: Tue Nov 04, 2008 8:40 am
by tonyledenko
Thank you, your "if" statement works perfect!