Coding syntax question
6 posts by 3 authors in: Forums > CMS Builder
Last Post: August 7, 2009 (RSS)
By gkornbluth - August 6, 2009
I’ve been using an e-mail address encryption program to keep bots from harvesting e-mail addresses from my pages.
I’m having trouble with the code syntax that I need to embed a graphic in the link instead of text.
Here’s the code in question:
<?php echo $emailcode->emailgetencode($common_informationRecord['contact_e_mail'],'click here to e-mail us','','special','xhtml');
?>
Which pulls the e-mail address from a “contact_email” field.
I can embed a single graphic with code like this to replace the “click here to e-mail us” text.
<?php echo $emailcode->emailgetencode($common_informationRecord['contact_e_mail'],'<img border="0" src="images/email.png">','','special','xhtml');
?>
When I try to pull the e-mail address from the “contact_e-mail field” and the graphic from the upload field “email_graphic”, I can’t seem to get the syntax right and I’m greeted by that dreaded blank white screen.
Any direction would be appreciated.
Best,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Coding syntax question
By Dave - August 6, 2009
Try the code in this post to enable error reporting. That should give you a better clue what's going on.
http://www.interactivetools.com/forum/gforum.cgi?post=66917#66917
Let me know if that helps or provides any more details.
interactivetools.com
Re: [Dave] Coding syntax question
By gkornbluth - August 7, 2009
I tried the error reporting code, but still get only a blank screen and source.
Here's the generic layout of the code I'm using:
<?PHP echo $emailcode->emailgetencode($record['e_mail'],'VISIBLE TEXT','Your mail subject','YOURCLASS','xhtml'); ?>
With this code above it in the body.
<?PHP
require 'emailcode.class.php';
$emailcode = new ClassEmailcode();?>
I've attached the emailcode.class.php file just to be complete._____________
Here's the code that works to replace the VISIBLE TXT with an image
<?php echo $emailcode->emailgetencode($common_informationRecord['contact_e_mail'],'<img border="0" src="images/email.png">','','special','xhtml');
?>
Here's the actual code that I'm trying to implement to replace the VISIBLE TXT with an image from the database.
<?php echo $emailcode->emailgetencode($common_informationRecord['contact_e_mail'],'<img src="<?php foreach ($common_informationRecord['e-mail_logo'] as $upload): ?><?php echo $upload['thumbUrlPath'] ?>" border="0" />
<?php endforeach ?>','','special','xhtml');
?>
I'm pretty sure that it has something to do with the way trying to put one php call inside another, but I don't know how to fix it.
Thanks,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Coding syntax question
By Chris - August 7, 2009
Yes, you cannot put PHP tags inside of a string inside of PHP. Here's an alternate approach:
The following code will find the first image in the e-mail_logo field and generate an <img> tag for it, or use the string "click here to e-mail us" if no image is available, then pass that off to $emailcode->emailgetencode().
<?php
$visibleText = "click here to e-mail us";
foreach ($common_informationRecord['e-mail_logo'] as $upload):
if ($upload['isImage']):
$visibleText = "<img src=".$upload['thumbUrlPath']." width=".$upload['width']." height=".$upload['height']." alt='' />";
break;
endif;
endforeach;
echo $emailcode->emailgetencode($common_informationRecord['contact_e_mail'],$visibleText,'','special','xhtml');
?>
Please let us know if this solves your problem.
Chris
Re: [chris] Coding syntax question
By gkornbluth - August 7, 2009 - edited: August 12, 2009
It certainly is easier when you understand the finer points...
Your solution worked like a charm.
One question:
What do the periods indicate before and after things like:
width=".$upload['width']."
Thanks again,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Coding syntax question
By Chris - August 7, 2009
The period is the [url http://www.php.net/manual/en/language.operators.string.php]concatenation operator in PHP[/url], which joins two string together.
Glad this worked for you!
Chris