CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> CodeChargeStudio.Discussion

 PHP et al: How do I embed code into the page?

Print topic Send  topic

Author Message
Chip Cotton
Posted: 06/29/2002, 12:19 PM

I want to stick some code in the middle of a page, but I don't see
where.

It seems that the generated code wants to parse out the 'html' page
without processing any <? --- ?> tags.

When I stick some code in the middle example: <? echo "hello!"; ?> it
embeds it into the HTML (the <?'s make it invisible to the viewer).

I've read most of the manual, OK? But this one escapes me, and I'm
SURE you can do this... But how?
Brent
Posted: 06/29/2002, 3:25 PM

Chip Cotton <please.no.email@Jail-Spammers.com> wrote:

:I want to stick some code in the middle of a page, but I don't see
:where.
:
:It seems that the generated code wants to parse out the 'html' page
:without processing any <? --- ?> tags.
:
:When I stick some code in the middle example: <? echo "hello!"; ?> it
:embeds it into the HTML (the <?'s make it invisible to the viewer).
:
:I've read most of the manual, OK? But this one escapes me, and I'm
:SURE you can do this... But how?

Chip,
If you want to embed PHP code into a page, then use one of the
embed points like "Server/Before Show". This will get executed just
before the page is displayed (good for changing titles). You also have
the ability to add embeded code for each field (change the field value
before it gets displayed) or for each time a row in the grid is
displayed.

To the best of my knowledge you can't add PHP code to the HTML
window. The HTML window is used for formatting the screen.

Brent
Chip Cotton
Posted: 06/29/2002, 3:51 PM

Thanks for getting back.

Actually, I have found that one can pretty much do this when you've
inserted just a label and you can assign it a calculated value
example:

function Label1_BeforeShow() { //Label1_BeforeShow @4-4ABEF0EE

//Custom Code @5-2A29BDB7
global $Label1; // note: global directive required...
$showme = "it works!";
$Label1->setvalue($showme);
//End Custom Code
} //Close Label1_BeforeShow @4-FCB6E20C

Label1 will display the $showme variable.

Actually, however, what I REALLY would like to do is to include a
file, NOT a codecharge file, but an externally edited text file in a
specific part of the page.

> To the best of my knowledge you can't add PHP code to the HTML
>window. The HTML window is used for formatting the screen.

I have found this statement to be correct, however, in that I am
unable to *strategically* insert a INCLUDE within the layout.

I even tried this as an include file (check this out for tenacity!):

within the include file:
<? $include_this = "html and other text information"; ?>

....And then in the before show event of label1:
include "include_text.php";
$Label1->setvalue($include_this);

This actually works, *BUT*

....CodeCharge Studio parses all of the quotes and HTML to straight
text! (rendering ""e;" stuff, etc.)

I'd really like to know if there's a work around to this.

To be honest, I've rolled back to CodeCharge 2 to get my work done...

On Sat, 29 Jun 2002 17:29:29 -0500, Brent <bdgridly@mailbolt.com>
wrote:
> If you want to embed PHP code into a page, then use one of the
>embed points like "Server/Before Show". This will get executed just
>before the page is displayed (good for changing titles). You also have
>the ability to add embeded code for each field (change the field value
>before it gets displayed) or for each time a row in the grid is
>displayed.
>
Brent
Posted: 06/29/2002, 7:00 PM

Chip Cotton <please.no.email@Jail-Spammers.com> wrote:

:Thanks for getting back.
:
:Actually, I have found that one can pretty much do this when you've
:inserted just a label and you can assign it a calculated value
:example:
:
:function Label1_BeforeShow() { //Label1_BeforeShow @4-4ABEF0EE
:
://Custom Code @5-2A29BDB7
: global $Label1; // note: global directive required...
: $showme = "it works!";
: $Label1->setvalue($showme);
://End Custom Code
:} //Close Label1_BeforeShow @4-FCB6E20C
:
:Label1 will display the $showme variable.
:
:Actually, however, what I REALLY would like to do is to include a
:file, NOT a codecharge file, but an externally edited text file in a
:specific part of the page.
:
:> To the best of my knowledge you can't add PHP code to the HTML
:>window. The HTML window is used for formatting the screen.
:
:I have found this statement to be correct, however, in that I am
:unable to *strategically* insert a INCLUDE within the layout.
:
:I even tried this as an include file (check this out for tenacity!):
:
:within the include file:
:<? $include_this = "html and other text information"; ?>
:
:...And then in the before show event of label1:
:include "include_text.php";
:$Label1->setvalue($include_this);
:
:This actually works, *BUT*
:
:...CodeCharge Studio parses all of the quotes and HTML to straight
:text! (rendering ""e;" stuff, etc.)
:
:I'd really like to know if there's a work around to this.

Hmmm, let's see why it doesn't work.

Include("myphpcode.php");
will include the php code "myphpcode.php" into that section of the
embed point. Includes are typically for embedding PHP code into your
existing PHP code. But you're trying to trick it to assign HTML code
to a field.

Do you remember the old adage that goes something like "When you have
a hammer, everything starts to look like a nail?"<bg>

If I understand you correctly,

1) You would like to put HTML code into Label1.
Go to the IDE and select A>{label1}<A then go to the Data tab of the
Properties window and set Content to HTML (it defaults to Text)-Boy
they really hid this option well, didn't they<g>. So now the field
will accept HTML. So far so good.

2) You want to load the HTML from a file and not embed the HTML inside
PHP code. This allows you to update the HTML from outside sources,
right? Ok, so use PHP code to read the HTML file and put it into a PHP
variable. It goes something like this.

//--some before show embed point that executes only once--
global $myformname; //gives you access to your form var's
$filename = "myhtml.html"; //You may need to specify a directory
$fp = fopen($filename, "r"); //open file as read
$array = file($filename); //load the data into an array
fclose($fp);
$html_str = implode("<BR>",$array); //replace returns with break??
$myformname->Label1->setvalue($html_str); //label gets the html string

Now the Label1 has the HTML string and should display properly on the
screen. Make sure the case for $myformname and Label1 are correct.
They must match the definitions in the IDE.

Ok, that's it. (Now put that hammer away!<g>)

:
:To be honest, I've rolled back to CodeCharge 2 to get my work done...

Yes, I know CC2 is tempting to go back to. But after a while CCS
starts to make sense.

Brent
Chip Cotton
Posted: 06/29/2002, 8:26 PM

The "Content" tip did the trick! Here are my notes...:

On Sat, 29 Jun 2002 21:04:29 -0500, Brent <bdgridly@mailbolt.com>
wrote:
>Include("myphpcode.php");
>will include the php code "myphpcode.php" into that section of the
>embed point. Includes are typically for embedding PHP code into your
>existing PHP code. But you're trying to trick it to assign HTML code
>to a field.

Yes and no. That is, I want to use it for both, I want to be able to
process some information via PHP and have it output at a particular
place. I want to put that code (such as a header or a footer, or a
banner rotator, etc) into a file which can then be put in any number
of pages for the usual reasons. The most simple application was,
however, to include a header (Codecharge insists upon screwing around
with the formatting of my HTML tables)

>1) You would like to put HTML code into Label1.
>Go to the IDE and select A>{label1}<A then go to the Data tab of the
>Properties window and set Content to HTML (it defaults to Text)-Boy
>they really hid this option well, didn't they<g>. So now the field
>will accept HTML. So far so good.

AHH! ..and I was thinking the 'Content' options were like
Text/Date/Integer/etc!

>2) You want to load the HTML from a file and not embed the HTML inside
>PHP code. This allows you to update the HTML from outside sources,
>right? Ok, so use PHP code to read the HTML file and put it into a PHP
>variable. It goes something like this.
>
>//--some before show embed point that executes only once--
>global $myformname; //gives you access to your form var's

Do I really need a form? A straight up label works fine without this
tag. Furthermore, the form tag screws around with my table formatting
(graphics split up and put into tables to appear as one graphic). I
just want the text to output with no <p> or <br> etc..

>$filename = "myhtml.html"; //You may need to specify a directory
>$fp = fopen($filename, "r"); //open file as read
>$array = file($filename); //load the data into an array
>fclose($fp);

UGH!

>$html_str = implode("<BR>",$array); //replace returns with break??
>$myformname->Label1->setvalue($html_str); //label gets the html string

I was hoping to avoid this fopen/read/fclose for the added operation
on the server side, when what I really want to do is so simple via the
include statement. (one operation versus four, including the setting
of the label's value)

Why do you think Codecharge has shielded us from embedding code into
the HTML when it's such a basic feature of PHP? I can only suspect
they did so because mixing code with HTML is not a feature of Perl,
but it seems so removed from the spirit of PHP.

I appreciate the code breakout above, however, as I have a feeling
I'll end up using it sometime soon.

I've found that using the method I described before, however, works!

Use the include statement, but have the .inc'd file put everything
into a named $variable, then set the label's value to that $var.
Works fine.

Now maybe I'll give Studio another try...
Brent
Posted: 06/29/2002, 8:59 PM

Chip Cotton <please.no.email@Jail-Spammers.com> wrote:

:The "Content" tip did the trick! Here are my notes...:
:
:
:AHH! ..and I was thinking the 'Content' options were like
:Text/Date/Integer/etc!

Yes, it took me a while to find it too. They misnamed it as far as I'm
concerned.


:>$html_str = implode("<BR>",$array); //replace returns with break??
:>$myformname->Label1->setvalue($html_str); //label gets the html string
:
:I was hoping to avoid this fopen/read/fclose for the added operation
:on the server side, when what I really want to do is so simple via the
:include statement. (one operation versus four, including the setting
:of the label's value)

If you can get it to work with Include(), then go for it.<g>

:
:Why do you think Codecharge has shielded us from embedding code into
:the HTML when it's such a basic feature of PHP? I can only suspect
:they did so because mixing code with HTML is not a feature of Perl,
:but it seems so removed from the spirit of PHP.
:
:I appreciate the code breakout above, however, as I have a feeling
:I'll end up using it sometime soon.
:
:I've found that using the method I described before, however, works!
:
:Use the include statement, but have the .inc'd file put everything
:into a named $variable, then set the label's value to that $var.
:Works fine.

I suppose you know the Include() in PHP 4 can return a value, like:
$retval = include ('test.php');

:
:Now maybe I'll give Studio another try...
There you go. :)

Brent

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.