echo statement in form

Reply

Join Date: Sep 2008
Posts: 5
Reputation: tonyledenko is an unknown quantity at this point 
Solved Threads: 0
tonyledenko tonyledenko is offline Offline
Newbie Poster

echo statement in form

 
0
  #1
Nov 3rd, 2008
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.

<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>

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:
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: echo statement in form

 
0
  #2
Nov 3rd, 2008
this should do it.

  1. <?php
  2.  
  3. $array = array(
  4. 'Name'=>'fullname',
  5. 'Company'=>'company',
  6. 'Phone'=>'phone',
  7. 'Email'=>'email',
  8. 'Address'=>'address',
  9. 'City'=>'city',
  10. 'State'=>'state'
  11. );
  12.  
  13. $html = '';
  14. foreach( $array as $title => $value ) {
  15. $str = ${$value};
  16. if ( $str !== '' ) {
  17. $html .= "<span class=\"content\"><strong>{$title}:</strong>&nbsp;</span>\n";
  18. $html .= "<span class=\"contentred\">{$str}</span><br />\n";
  19. }
  20. }
  21.  
  22. echo $html;
  23.  
  24. ?>

i know theres another way to do it but i can't think of it right now.
Last edited by kkeith29; Nov 3rd, 2008 at 8:27 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC