Click to See Complete Forum and Search --> : Template Builder


The Anime King
03-31-2005, 07:44 AM
I'm trying to make a template builder, but I'm having trouble with the coding...
I'll show you what I have so far:

<form name=templatebuilder>
<input name=fgcolor>
<input name=bgcolor>
<select name=border>
<option>inset</option>
<option>outset</option>
</select>
<input type=submit>
<iframe src=template.php></iframe>
</form>

Now comes the hard part. If you press submit, I would like the template to be updated. So if you fill in Red as fgcolor and press Submit, template.php?fgcolor=red is opened in the iframe. Is this possible, and what will the code be?
Thanx!

NogDog
03-31-2005, 02:30 PM
If I'm correctly understanding the question, I think you'd need something like this:

<form name=templatebuilder action='<?php echo($_SERVER['PHP_SELF']); ?>' method=post>
<input name=fgcolor>
<input name=bgcolor>
<select name=border>
<option>inset</option>
<option>outset</option>
</select>
<input type=submit name=do_it>
<?php
$style = "";
if(isset($_POST['do_it']))
{
$style = " style='background-color: {$_POST['bgcolor']}; color: {$_POST['fgcolor']}; border-style: {$_POST['border']};'";
}
echo "<iframe src=template.php$style>";
?>
</iframe>
</form>

The Anime King
03-31-2005, 02:53 PM
Not exactly what I was looking for, and it didn't even work, i'm sorry :(

I'll change the question :)
How can I make the script, so that it writes the value in a textarea?
So there's a textarea that will write down:
Fg = red
Bg = green
Border = outset

That will be closer to what I'm looking for... Thanx! :)

ShrineDesigns
03-31-2005, 03:28 PM
first, you need valid html http://validator.w3.org/

then for the value do this:<textarea id="textbox" name="textbox"><?php echo (isset($_POST)) ? htmlspecialchars(stripslashes($_POST['textbox'])) : ''; ?></textarea>or<input type="text" id="field" name="field" value="<?php echo (isset($_POST)) ? htmlspecialchars(stripslashes($_POST['field'])) : ''; ?>">

solomon
03-31-2005, 05:24 PM
Well, let's see if I've understood the question properly. It's only quickly knocked together so I haven't had a chance to validate the source code.

Firstly, it's not essential, but let's set a few variables:
<?php
$fgcolour = "#333355";
$bgcolour = "#F8F8FF";
$bdcolour = "#666666";
$bdwidth = "3";
$bdstyle = "inset";
?>

Then let's sort most of the form out:

<form name="templateform" method="post" action="template.php" target="displaytemplate">
foreground colour:
<input name="fgcolour" type="text" id="fgcolour" value="<? echo $fgcolour; ?>">
<p />
background colour:
<input name="bgcolour" type="text" id="bgcolour" value="<? echo $bgcolour; ?>">
<p />
border colour:
<input name="bdcolour" type="text" id="bdcolour" value="<? echo $bdcolour; ?>">
<p />
border width:
<input name="bdwidth" type="text" id="bdwidth" value="<? echo $bdwidth; ?>"> pixels

Then the drop down menu bit of the form. I like to do it like this:

<p />
border style:
<select name="bdstyle" id="bdstyle">
<?php
$elements = array('inset','outset','dotted','dashed','solid','double','groove','ridge');
foreach($elements as $values1) {
if ($bdstyle == $values1) {
$selected = " selected";
} else {
$selected = "";
}
echo " <option value=\"".$values1."\"".$selected.">".$values1."</option>\n";
}
?>
</select>

And finally, close the form and stick in the iframe:

<p />
<input name="testit" type="submit" id="testit" value="Test it">
</form>
<iframe name="displaytemplate" id="displaytemplate"></iframe>

Consecutively copy and paste all the above excerpts to form one script and call it index.php

Then copy and paste this code and save it in the same directory as template.php:
<body bgcolor="<? echo $bgcolour; ?>" text="<? echo $fgcolour; ?>">
<table style="border: <? echo $bdwidth."px ".$bdcolour." ".$bdstyle; ?>;">
<tr>
<td>This is a demonstration </td>
</tr>
</table>
</body>

Upload and run index.php - it works quite nicely for me but I guess it's only one solution.

I hope it's the sort of thing you're after - if not, n/m, it was fun sorting it out :)

If you want to see my version it's uploaded here (http://www.thrutch.co.uk/code/webdeveloper/templategenerator/)

The Anime King
04-01-2005, 12:23 PM
That was perfect :D

I customized it and now it works great!

I have one last thing that doesn't work yet though...

I would like a little Textarea in the bottom that displays the values of everything submitted in php code, so if you submit, the iframe changes into a preview, and the textarea changes to
index.php?fg=red&bg=green&font=arial...

The iframe should be updated, but the textarea is not to be put in the iframe. Is this possible? Thanx!

solomon
04-01-2005, 05:26 PM
would be easily done if the textarea was to be in the iframe as part of 'template.php' because in order to get the new content into it the page needs refreshing - the parent page, index.php, never refreshes! It would be solvable in javascript but I'm not the guy for that I'm afraid :(

solomon
04-01-2005, 06:27 PM
This is a fairly neat solution (http://www.thrutch.co.uk/code/webdeveloper/templategenerator/index.php)

You can view the php source code from the page so I won't post it here. Main basic change is altering the form method in index.php from POST to GET. This passes the full ugly URL to the template.php. You can then grab that URL using $_SERVER['REQUEST_URI'] and display it however you want. It is within the iframe, I'm afraid, but I tried sorting it to appear in the the parent but I lost patience with how ugly the code was getting :p