/    Sign up×
Community /Pin to ProfileBookmark

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:

[code=php]<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>[/code]

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!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 31.2005 — If I'm correctly understanding the question, I think you'd need something like this:
[code=php]
<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>
[/code]
Copy linkTweet thisAlerts:
@The_Anime_KingauthorMar 31.2005 — 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! ?
Copy linkTweet thisAlerts:
@ShrineDesignsMar 31.2005 — first, you need valid html http://validator.w3.org/

then for the value do this:[code=php]<textarea id="textbox" name="textbox"><?php echo (isset($_POST)) ? htmlspecialchars(stripslashes($_POST['textbox'])) : ''; ?></textarea>[/code]or[code=php]<input type="text" id="field" name="field" value="<?php echo (isset($_POST)) ? htmlspecialchars(stripslashes($_POST['field'])) : ''; ?>">[/code]
Copy linkTweet thisAlerts:
@solomonMar 31.2005 — 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:
[code=php]<?php
$fgcolour = "#333355";
$bgcolour = "#F8F8FF";
$bdcolour = "#666666";
$bdwidth = "3";
$bdstyle = "inset";
?>[/code]


Then let's sort most of the form out:

[code=html]<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 [/code]


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

[code=php]<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>[/code]


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

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


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:
[code=html]<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>[/code]


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 ?

[URL=http://www.thrutch.co.uk/code/webdeveloper/templategenerator/]If you want to see my version it's uploaded here[/URL]
Copy linkTweet thisAlerts:
@The_Anime_KingauthorApr 01.2005 — That was perfect ?

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!
Copy linkTweet thisAlerts:
@solomonApr 01.2005 — 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 ?
Copy linkTweet thisAlerts:
@solomonApr 02.2005 — [URL=http://www.thrutch.co.uk/code/webdeveloper/templategenerator/index.php]This is a fairly neat solution[/URL]

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 [I]is[/I] 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
×

Success!

Help @The_Anime_King spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...