changing the value of a variable in an object through a butt

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grief
Forum Newbie
Posts: 3
Joined: Sun Feb 09, 2003 4:08 am
Location: Far Far up a tree

changing the value of a variable in an object through a butt

Post by grief »

Im kind of a newbie at this and i was hoping for some help.
Im working on a class that will spawn a module type of object around content by typing the following into the body of my main page.

<?php
$a = new module("n","title","lots and lots of content");
echo $a->printit();
?>

the code to the actual class is as follows

<?php /* Spawn Module */
class module {
var $minimized;
var $title = "";
var $body = "";

function module ($m,$t,$b) {
$this->minimized = $m;
$this->title = $t;
$this->body = $b;
}

function printit() {

if ($this->minimized == "y") {

html code and junk for the minimized object
}
if ($this->minimized == "n") {

html code and junk for the maximized object
}
}
}

I pasted that in so its kinda sloppy but what i need help with is in the
if ($this->minimized == "y") { part of it i have html that make up the window wnd stuf and within the html i have a image button that when you click it i want to tell the object that $this->minimized = n ;
so i can do the opposite in the html code of the if ($this->minimized == "n") { part of is so i can get a minimizeing and maxamizing action going on but im not sure how to tell the object in a image type of button that the value of $this->minimized has changed to eithier y or n.

i have found stuff on how to write and structure classes but nothing on changing the value of a variable in an object through a button or something.

anything would help
thanks...
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Post by Skywalker »

If understood you well, then the easyest way to make somethings like the body and title etc. you best could make an php file with the variables in it.

example:

Code: Select all

<?php
$body       = bgcolor="black";
$body2     = bgcolor="white";
$font        = font face="verdana";
$font2      = font face="arial";
$tdwidth   = td width="500";
$tdwidth2 = td width="450";
?>

this litle file you could the include in everypage, it's easy editable.
because your are using for everypage the include option.

I hope I understood you well

Greathings Skywalker
grief
Forum Newbie
Posts: 3
Joined: Sun Feb 09, 2003 4:08 am
Location: Far Far up a tree

Post by grief »

I already use cascading style sheets to set bgcolor and all of that because all i need to put in the head of anypage is
<link rel="stylesheet" href="style1.css" type="text/css"/>
plus with using style sheets i can allow users to change the look and feel of my site.

What i need help with is a class that i created and saved in a seperate file called library.php and at the top of my main page i put
<?php require("library.php"); ?>

and i use the class in the body of the page with this
<?php
$a = new module("n","Title Here","Content content and more content"); echo $a->printit();
?>

that will insert a bunch of html into the page and in the midle of it all i have a button i want to use to tell the class or object to change the value of $this->minimized = "";
to
$this->minimized = "y";
or
$this->minimized = "n";
how would i go about doing that? my guess was

<a href="$PHP_SELF?this->minimized=y">

i tried a bunch of things like

<a href="$PHP_SELF?minimized=y">

but no luck.
I apreciate any help
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

php is server-side, the button rendered by the browser is client-side. There is no connection between these two worlds as soon as the document is delivered. You would need a complete new document request to bring php back in the game.
If you open the "source view" of your browser you will see that there are no <?php ... ?> blocks anymore (if your php-module/cgi is working ;) ), because they have been replaced by the output generated by these blocks and this has taken place server-side, before the client received the document (not entirely correct but sufficient here). To catch client-side events you need a client-side script language such as javascript. e.g.

Code: Select all

<html>
<head>
	<style type="text/css">
		button &#123; &#125;
		button.highlight &#123; color: white; background-color: blue; &#125;
	</style>
	<script type="text/javascript">
		function toggle(elem)
		&#123;
			if (elem.className.length > 0)
				elem.className = "";
			else
				elem.className = "highlight";
		&#125;
	</script>
</head>
<body>
<button onClick="javascript:toggle(this)">toggle style</button>
</body></html>
Post Reply