vicdesigns Posted June 17, 2011 Share Posted June 17, 2011 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. Quote Link to comment Share on other sites More sharing options...
pornophobic Posted June 18, 2011 Share Posted June 18, 2011 I won't solve it for you, but something handy is to check that your responses aren't empty with something like this: if (empty($var) || $var === '') { //do nothing } else { //send image } Quote Link to comment Share on other sites More sharing options...
vicdesigns Posted June 18, 2011 Author Share Posted June 18, 2011 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. Quote Link to comment Share on other sites More sharing options...
vicdesigns Posted June 19, 2011 Author Share Posted June 19, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.