boondocksaint
05-04-2005, 06:37 PM
Hi, I'm starting to learn PHP.
Usually; when working with forms the action is another page; but here I'm trying to use the same page for action.
The problem is that since PHP code which looks at the variable that is posted from the form is on the same page. When first opening the page, I get Undefined Variable messages.
<?
if ($themes == 'Neutral'){ // Theme: Neutral
echo '<body bgcolor="gray">';
} else if ($themes == 'Dark'){ // Theme: Dark
echo '<body bgcolor="black">';
} else if ($themes == 'Light'){ // Theme: Light
echo '<body bgcolor="white">';
} else {
// Do nothing!
}
?>
<table align="center"><tr><td>
<form action="<? $PHP_SELF ?>" method="post">
<select name="themes">
<option value="Neutral" selected="selected">Neutral</option>
<option value="Dark">Dark</option>
<option value="Light">Light</option>
</select>
<p align="center"><input name="submit" type="submit" value="OK"></p>
</form>
</td></tr></table>
<?
echo '</body>';
?>
Unfortunately defining the variable in the script would overwrite the value recieved from the form. How would I go about getting rid of the problem and still use the same file (as in: no "handle_themes.php", etc...)?
Thank you.
Usually; when working with forms the action is another page; but here I'm trying to use the same page for action.
The problem is that since PHP code which looks at the variable that is posted from the form is on the same page. When first opening the page, I get Undefined Variable messages.
<?
if ($themes == 'Neutral'){ // Theme: Neutral
echo '<body bgcolor="gray">';
} else if ($themes == 'Dark'){ // Theme: Dark
echo '<body bgcolor="black">';
} else if ($themes == 'Light'){ // Theme: Light
echo '<body bgcolor="white">';
} else {
// Do nothing!
}
?>
<table align="center"><tr><td>
<form action="<? $PHP_SELF ?>" method="post">
<select name="themes">
<option value="Neutral" selected="selected">Neutral</option>
<option value="Dark">Dark</option>
<option value="Light">Light</option>
</select>
<p align="center"><input name="submit" type="submit" value="OK"></p>
</form>
</td></tr></table>
<?
echo '</body>';
?>
Unfortunately defining the variable in the script would overwrite the value recieved from the form. How would I go about getting rid of the problem and still use the same file (as in: no "handle_themes.php", etc...)?
Thank you.