Gossamer Forum
Home : Products : DBMan : Installation :

Show only fields with data in them

Quote Reply
Show only fields with data in them
I know you've covered this but I'm having trouble finding it. Can you point me to the thread or help me? I am i need of help...

If a record is added and some of the fields are left blank I would like to hide the fields when someone does a search and pulls up the records. So if nothing was entered into 'name' i'd like that not to be displayed but do want the rest of the info for that record displayed. Also aside from hiding 'name' I would not like the name: adjacent to it to show up and if there is a default value like http:// in a field but the rest of that field has not been completed (i.e., http://www.somesite.com) can we hide the default value as well. I am a real beginner and need to be told exactly where to insert the code.

Sorry for my ignorance. I did try an example I found in another thread but couldn't get it working. So I thought I'd try with a fresh new thread.

Craig (wave3)
Quote Reply
Re: Show only fields with data in them In reply to
Should I be?
Quote Reply
Re: Show only fields with data in them In reply to
Okay.

Then you have something like:

Code:
print qq|
<table>
<tr><td>Name:</td>
<td>$rec{'Name'}</td></tr>
<tr><td>Address:</td>
<td>$rec{'Address'}</td></tr>
<tr><td>City</td>
<td>$rec{'City'}</td></tr>
<tr><td>State</td>
<td>$rec{'State'}</td></tr>
<tr><td>Website</td>
<td><a href="$rec{'URL'}">$rec{'URL'}</td></tr>
</table>
|;

in you html_record.

You will only have to worry about this with non-required fields, since you know that required fields will have an entry.

Let's say that in my example, the Name and State fields are required. Also that the URL field has a default value of "http://" which may still be in the field, even if the user didn't enter a URL.

You would make the following changes:

Code:
print qq|
<table>
<tr><td>Name:</td>
<td>$rec{'Name'}</td></tr>|;
if ($rec{'Address'}) {
print qq|

<tr><td>Address:</td>
<td>$rec{'Address'}</td></tr>|;
}
if ($rec{'City'} {
print qq|

<tr><td>City</td>
<td>$rec{'City'}</td></tr>|;
}
print qq|

<tr><td>State</td>
<td>$rec{'State'}</td></tr>|;
if ($rec{'URL'} ne "http://") {
print qq|

<tr><td>Website</td>
<td><a href="$rec{'URL'}">$rec{'URL'}</td></tr>|;
}
print qq|

</table>
|;

Make sense?


------------------
JPD





Quote Reply
Re: Show only fields with data in them In reply to
Are you using the "autogenerate" feature?


------------------
JPD





Quote Reply
Re: Show only fields with data in them In reply to
No I am not.
Quote Reply
Re: Show only fields with data in them In reply to
JPDeni is my mentor..... It is working all but one tiny thing. It hides the URL info and even the default http:// as I wished. It doesnt however hide the email or mailto: default value one nothing is typed in the field. Im guessing I need something in place of the "ne". Here is my code. Do you see the problem?

code:

if ($rec{'Hours'}) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Hours:</FONT></TD>
<td>$rec{'Hours'}</td></tr>|;
}
if ($rec{'URL'} ne "http://") {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Website:</FONT></TD>
<td><a href="$rec{'URL'}">$rec{'URL'}</td></tr>|;
}
if ($rec{'Email'} ne "Mailto:") {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Email:</FONT></TD>
<td><a href="$rec{'Email'}">$rec{'Email'}</td></tr>|;
}
Quote Reply
Re: Show only fields with data in them In reply to
I wouldn't put the "Mailto:" as a default value in your field definition. I would leave it blank.

Then you could use:

Code:
if ($rec{'Email'} ne "Mailto:") {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP"
WIDTH="20%"><$font_color>Email:</FONT></TD>
<td><a href="mailto:$rec{'Email'}">$rec{'Email'}</td></tr>|;
}

If you want to keep the default value of the email field, make sure that your

($rec{'Email'} ne "Mailto:")

is exactly the same as the default value in your field definition. And remember that case counts. "Mailto:" is not the same as "mailto:".

------------------
JPD





Quote Reply
Re: Show only fields with data in them In reply to
I have made the change and it certainly looks better not having "mailto:" in the field although if the field is not filled out the field name still shows up "Email:" with the blank field next to it. This doesn't happen with the Website: field or any other. If they are not filled out they won't show up as a field name or entry in the record. I have changed nothing and am completely at a loss. The default .cfg has nothing strange in it. Any thoughts. Any wisdom you might throw my way?
Quote Reply
Re: Show only fields with data in them In reply to
I hope you weren't racking your brain... I got it stupid mistake on my part.. I forgot to remove the ne mailto.. It works great!!!! Thanks as always, people hire jpdeni for awesome servide
Quote Reply
Re: Show only fields with data in them In reply to
  Smile

Glad you worked it out.

BTW, if you want to make sure email addresses are in the correct format, use the following in the last section of the field definition for your email field:

'.+\@.+\..+'

That will assure everything is in the form of "something@something.something". It won't guarantee it's a real email address, but it will stop folks from just entering something like "fred" in the field. (AOL folks are notorious for that.)

------------------
JPD







[This message has been edited by JPDeni (edited July 13, 1999).]