...

View Full Version : Generator Help



Rappa
08-04-2007, 05:41 PM
Hello all. I'm attempting to make a Table Generator in PHP. So far so good, although i'm a very novice coder, I can manage to get by with what I know with probably more difficult ways than i have to. Anyway heres my problem:

So you have all the feilds where you input data right, then you have the submit button, and the text area where the code is shown. Well once the values are inputted, and the button is clicked, the code is shown, however, all the feilds above just go blank. I want the values in the feilds to stay in the form until the user clicks the reset button.

Heres what I have so far: Id appreciate it if no one made fun of my code, i'm just starting to learn PHP, and besides this isnt done yet.


<?php
$table = "<table";
$tableclose = ">";

if ($cellpadding != "") {
$padding = " " . "cellpadding" . "=" . "\"" . $cellpadding . "\"";
}
else {
$padding = "";
}
if ($cellspacing != "") {
$spacing = " " . "cellspacing" . "=" . "\"" . $cellspacing . "\"";
}
else {
$spacing = "";
}
if ($bordersize != "") {
$border = " " . "border" . "=" . "\"" . $bordersize . "\"";
}
else {
$border = "";
}
if ($width != "") {
$tablewidth = " " . "width" . "=" . "\"" . $width . "\"";
}
else {
$tablewidth = "";
}
if ($bordercolor != "") {
$borderc = " " . "bordercolor" . "=" . "\"" . $bordercolor . "\"";
}
else {
$borderc = "";
}
if ($bgcolor != "") {
$backgroundc = " " . "bgcolor" . "=" . "\"" . $bgcolor . "\"";
}
else {
$backgroundc = "";
}

$tableopen= $table . $padding . $spacing . $border . $tablewidth . $borderc . $backgroundc . $tableclose;

if ($submit == "Generate!") {
$result = $tableopen;
}

if ($reset == "Reset") {
$result = "";
}
?>
<form method=post action=<?php print $PHP_SELF; ?>>
<table align="center"><tr><td>
<table cellspacing="5" border="0">
<tr align="left"><td>Number of Columns:</td><td><input type="text" size="5" name="columns"></td></tr>
<tr align="left"><td>Number of Rows:</td><td><input type="text" size="5" name="rows"><td></tr>
<tr align="left"><td>Cell Padding:</td><td><input type="text" size="5" name="cellpadding"><td></tr>
<tr align="left"><td>Cell Spacing:</td><td><input type="text" size="5" name="cellspacing"><td></tr>
<tr align="left"><td>Border Size:</td><td><input type="text" size="5" name="bordersize"></td></tr>
<tr align="left"><td>Width (Pixels or %):</td><td><input type="text" size="5" name="width"></td></tr>
<tr align="left"><td>Border Color:</td><td><input type="text" size="10" name="bordercolor"></td></tr>
<tr align="left"><td>Background Color:</td><td><input type="text" size="10" name="bgcolor"></td></tr>
<tr align="left"><td><input type="submit" value="Generate!" name="submit"></tr></td></table>
<textarea cols="50" rows="8" name="result">
<?php echo $result; ?>
</textarea><BR>
<input type="submit" value="Preview" name="preview">
<input type="submit" value="Reset" name="reset"></td></tr></table>
</form>

but any suggestions on how to make my life easier while learning PHP would be nice too.

-Anthony

PappaJohn
08-04-2007, 05:57 PM
As an example:
Change this:


<tr align="left"><td>Cell Padding:</td><td><input type="text" size="5" name="cellpadding"><td></tr>

to:


<tr align="left"><td>Cell Padding:</td><td><input type="text" size="5" name="cellpadding" value="<?php echo $cellpadding ?>"><td></tr>

Rappa
08-04-2007, 06:15 PM
ahh alright cool, thanks for that. Now im not quite sure on how to go about generating the rows and cells. Any suggestions?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum