Jump to content

Hide Image if Field Is Left Blank


vicdesigns

Recommended Posts

Howdy folks,

 

I have an image to display if a required field is filled in. But what I want to do is if the field is left blank, to hide the image.

 

Here is the code for the field itself:

 

				<td align="left" width="150px">'._FACEBOOK_ADDRESS.'<font color="#c13a3a">*</font>: <img class="help" src="images/question_mark.gif" title="'._FACEBOOK_ALERT.'"></td>
			<td align="left" width="200px">
				<input type="text" name="facebook_address" size="30" maxlength="70" value="'.$params['facebook_address'].'">
			</td>

 

Here is the working code to display the image:

 

<a href='http://".$objSettings->GetParameter("facebook_address")."' title='"._FACEBOOK_ADDRESS."' target='_blank'><img src='images/facebook.png' alt='"._FACEBOOK_ALERT."' border='0'></a>

 

Here is the parameter:

 

	$params["facebook_address"] 	   = isset($_POST['facebook_address']) ? prepare_input($_POST['facebook_address']) : $objSettings->GetParameter("facebook_address");

 

I am stumped as to how to get the image to vanish if the field is left blank. Any help would be greatly appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/239643-hide-image-if-field-is-left-blank/
Share on other sites

Thanks.

 

I tried the following:

 

                        if ('"<a href='http://".$objSettings->GetParameter("")."');
echo "<tr>
		<td valign='bottom' style='".$text_align."'>
		<a href='feeds/rss.xml' title='RSS Feed'><img src='images/rss.png' alt='RSS Feed' border='0'></a> 
		<a href='index.php?page=contact' title='Contact Us'><img src='images/letter.gif' alt='"._EMAIL_ADDRESS."' border='0'></a>
		</td></tr>";

No goot. Just returned a Parse error: syntax error, unexpected T_STRING

I have never tried any of this before so am lost really.

Silly me. Got it:

 

			// Draw RSS & Email
		if($objSettings->GetParameter("facebook_address") == ""){
		$text_align = ($lang_dir == "ltr") ? "text-align: center;" : "text-align: right; padding-right:15px;";
		echo "<table class='moduletable' width='100%' border='0' cellspacing='0' cellpadding='0'>";
		echo "<tr>
		<td valign='bottom' style='".$text_align."'>
		<a href='feeds/rss.xml' title='RSS Feed'><img src='images/rss.png' alt='RSS Feed' border='0'></a> 
		<a href='index.php?page=contact' title='Contact Us'><img src='images/letter.gif' alt='"._EMAIL_ADDRESS."' border='0'></a>
		</td></tr>";	
		echo "</table>";}
					// Draw RSS Facebook & Email
		else {
		$text_align = ($lang_dir == "ltr") ? "text-align: center;" : "text-align: right; padding-right:15px;";
		echo "<table class='moduletable' width='100%' border='0' cellspacing='0' cellpadding='0'>";
		echo "<tr>
		<td valign='bottom' style='".$text_align."'>
		<a href='feeds/rss.xml' title='RSS Feed'><img src='images/rss.png' alt='RSS Feed' border='0'></a> 
		<a href='index.php?page=contact' title='Contact Us'><img src='images/letter.gif' alt='"._EMAIL_ADDRESS."' border='0'></a>
		<a href='http://".$objSettings->GetParameter("facebook_address")."' title='"._FACEBOOK_INVITE."' target='_blank'><img src='images/facebook.png' alt='"._FACEBOOK_INVITE."' border='0'></a>
		</td></tr>";	
		echo "</table>";}

 

Note the else statement.

Thanks anyways. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.