I Need HELP!!! Hiding empty fields...
Posted: Thu May 03, 2007 3:30 pm
pickle | Please use
The result that I get, when not filling in the "Secondary Phone" and "Secondary Email" , is:
Full Name:
John Smith
Primary Phone:
518-555-5555
Secondary Phone:
Primary Email:
123@4567.com
Secondary Email:
Comments:
hi there
As you can see, the empty fields are displayed. I want them to be hidden to look like this:
Full Name:
John Smith
Primary Phone:
518-555-5555
Primary Email:
123@4567.com
Comments:
hi there
Can anyone help me? The thing is, I have to use the current code. I appreciate it! Thank you!
Paul
pickle | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello,
I'm very new at PHP and I have this code written for school that I have to keep building off of. I'm almost complete with it, however I need to hide the empty fields when a user leaves a field blank when filling out form.
How do I write the php code when I want to hide the empty fields in this form and when using the present code???
For example (Here's the form:):
Full Name:
Primary Phone:
Secondary Phone:
Primary Email:
Secondary Email:
Comments:
Now, if the user enters info for everything except "Secondary Phone:" and "Secondary Email:, I only want that info displayed. For example: [b][u]IN OTHER WORDS, I DON'T WANT THE EMPTY FIELDS TO BE DISPLAYED[/u].[/b]
Full Name:
John Smith
Primary Phone:
518-555-1234
Primary Email:
1234@5678.com
Comments:
Hello
I'm very new at PHP so I may not even make sense half the time.
Here is my code: [syntax="php"]<?php
$fp=fopen("/studfs2/02441040/homepage/guestbook.txt","a");
fwrite($fp, "Full Name:~ ".$_POST["full_name"]);
fwrite($fp, "~Primary Phone:~ ".$_POST["primary_phone"]);
fwrite($fp, "~Secondary Phone:~ ".$_POST["secondary_phone"]);
fwrite($fp, "~Primary Email:~ ".$_POST["primary_email"]);
fwrite($fp, "~Secondary Email:~ ".$_POST["secondary_email"]);
fwrite($fp,"~Comments:~ ".$_POST["form_comments" ]."\n");
fclose($fp);
$fp=fopen("/studfs2/02441040/homepage/guestbook.txt","r");
while (!feof($fp)){
$items = fgets($fp); {
$pieces=explode("~",$items);
echo "$pieces[0]<br />";
echo "$pieces[1]<br />";
echo "$pieces[2]<br />";
echo "$pieces[3]<br />";
echo "$pieces[4]<br />";
echo "$pieces[5]<br />";
echo "$pieces[6]<br />";
echo "$pieces[7]<br />";
echo "$pieces[8]<br />";
echo "$pieces[9]<br />";
echo "$pieces[10]<br />";
echo "$pieces[11]<br /><br /><br />";
}
}
fclose($fp);
?>The result that I get, when not filling in the "Secondary Phone" and "Secondary Email" , is:
Full Name:
John Smith
Primary Phone:
518-555-5555
Secondary Phone:
Primary Email:
123@4567.com
Secondary Email:
Comments:
hi there
As you can see, the empty fields are displayed. I want them to be hidden to look like this:
Full Name:
John Smith
Primary Phone:
518-555-5555
Primary Email:
123@4567.com
Comments:
hi there
Can anyone help me? The thing is, I have to use the current code. I appreciate it! Thank you!
Paul
pickle | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]