Click to See Complete Forum and Search --> : [RESOLVED] Using PHP to declare Style Sheets for frames
jesterpunch
06-03-2007, 12:01 AM
Hello folks...
I have spent a great deal of time now attempting to declare Style Sheets from an external .css file for frames within a website.
This is what I have achieved so far:
http://theunsentletter.com/wdap/Assignment_2/
Please note the drop menu, select "Cronulla High" and press submit. You will see that all the text will become red. Please be impressed, finding the right code took me hours!
I must thank the person who created this thread:
http://www.webdeveloper.com/forum/showthread.php?t=89922
However when you click on the link, the sub page does not inherit the same style sheet as the frame that linked to it. I really need all my sub pages to inherit all the styles of these three starting frames. I intend to use frames so I can easily update the website (i.e. edit links in the side column) and style sheets so visitors can select their own school colours.
I fear that the problem is I should have used Javascript all along to declare which style sheet each page should use.
If this is the case can you please suggest what sort of script/form I use?
Or, if I only need to modify the existing pages, what should I do?
I also need a way to declare the default style sheet without user interaction (I don't want my into page to be Black and White). THus far I have no idea how!
Here are links to the frames:
http://theunsentletter.com/wdap/Assignment_2/title.php
http://theunsentletter.com/wdap/Assignment_2/linksColumn.php
http://theunsentletter.com/wdap/Assignment_2/introPage.php
http://theunsentletter.com/wdap/Assignment_2/introPage2.php
Sheldon
06-03-2007, 01:33 AM
Tables and iFrames? I hope that your not getting taught to use this in school.
jesterpunch
06-03-2007, 01:35 AM
School?
University...
The lectures don't tell me much...we're pretty much on our own.
They seriously gave us a crash course in every scripting language, One week we were learning CSS, then Javascrpt the next and then it was PHP. There's not much teaching going on at all.
Can you please suggest what I should use instead?
I need a way to make a page with a title and links column that is a seperate file, and I need to be able to implement style sheets.
Please help me... You know I need assistance but instead you have just criticised what I've done!
jesterpunch
06-03-2007, 04:08 AM
OK, I haven't managed to make DIVs work so I have stuck with tables.
However I am now using PHP inclusion and not iframes.
All in all things are looking cleaner:
http://theunsentletter.com/wdap/Assignment_2/index2.php
My problem still remains, when I select Cronulla High, everything turns red, which is good, but when you click on the link to the right, the style is lost.
Is there any way of using the selected style sheet on all the sub pages?
Or am I just crazy for using PHP to do this?
Basically what I am doing is using a submit form and the following script to define the style:
<?php $styleSheets=$_POST['styles'];?>
<link rel="stylesheet" type="text/css" href="styles/<?php print("$styleSheets");?>">
It works for the first page, but the style is lost when I click on following pages.
One way around this, I suppose, is to use an embedded PHP file for the main text (Right side) and sub-pages. However I tried this and when I clicked on the "come on in" link it filled up the parent window instead of remaining embedded in the index page... as well as losing the style.
Any feedback would be MOST appreciated!
Sheldon
06-03-2007, 05:47 AM
What you could do is use a session.
at the start or every page put <?php session_start(); ?> before anything else.
Then when you process that select how ever you do add this
$_SESSION['theme'] = $whatevercolorispassed;
then on each page include the session var to set the colours
Sheldon
06-03-2007, 05:49 AM
If you post your code so far i might be able to show you.
jesterpunch
06-03-2007, 06:02 AM
OK, here is my code...
At the moment I hope to use this layout as a template for sub-pages.
It's the "Please come on in" link that is troubling me as when I follow that link, tp a page that has the same layout as this one, the style is lost and I can't find any practical way to redefine it.
Thanks!
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
$styleSheets=$_POST['styles'];
?>
<link rel="stylesheet" type="text/css" href="styles/<?php print("$styleSheets");?>">
</head>
<body>
<table width="700" align="left" border="0">
<tr>
<td>
<?php include('title.php');?>
</td>
</tr>
<tr valign="top">
<td width="30%">
<b>Select your school's colours:</b><br>
<form name="styles" action="index2.php" method="post">
<select name="styles">
<option value="standard.css">Standard</option>
<option value="chs.css">Cronulla High</option>
<option value="khs.css">Kirrawee High</option>
</select>
<input type="submit" value="Submit">
</form>
<br>
<?php include('linksColumn.php');?>
</td>
<td width="70%">
<b>Please <a href="index3.php" target="_self">come on in</a></b>
</td>
</tr>
</table>
</body>
</html>
Sheldon
06-03-2007, 06:34 AM
try<?php
session_start();
if(isset($_POST['styles'])){
$_SESSION['styles'] = $_POST['styles'];
}
?><html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="styles/<?php echo($_SESSION['styles']);?>">
</head>
<body>
<table width="700" align="left" border="0">
<tr>
<td>
<?php include('title.php');?>
</td>
</tr>
<tr valign="top">
<td width="30%">
<b>Select your school's colours:</b><br>
<form name="styles" action="index2.php" method="post">
<select name="styles">
<option value="standard.css"<?php if($_SESSION['styles'] == "standard.css"){ echo(" selected=\"selected\" "); }?>>Standard</option>
<option value="chs.css"<?php if($_SESSION['styles'] == "chs.css"){ echo(" selected=\"selected\" "); }?>>Cronulla High</option>
<option value="khs.css"<?php if($_SESSION['styles'] == "khs.css"){ echo(" selected=\"selected\" "); }?>>Kirrawee High</option>
</select>
<input type="submit" value="Submit">
</form>
<br>
<?php include('linksColumn.php');?>
</td>
<td width="70%">
<b>Please <a href="index3.php" target="_self">come on in</a></b>
</td>
</tr>
</table>
</body>
</html>
jesterpunch
06-03-2007, 07:54 AM
Thanks for your help...
I shall try this tomorrow and use the same php script for my sub-pages.
Umm... should I edit this line?
<form name="styles" action="index2.php" method="post">
Sheldon
06-03-2007, 07:48 PM
<form name="styles" action="<?php echo(htmlentities($_SERVER['PHP_SELF'])); ?>" method="post">
jesterpunch
06-09-2007, 06:50 PM
Hi Sheldon,
Sorry for the late reply but THANKYOU
It worked a charm
Sheldon
06-09-2007, 07:08 PM
Good!. Make this thread as resolved in the thread tools menu, top right.