Jump to content
Larry Ullman's Book Forums

octavian

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by octavian

  1. I did it a little differently. Also here's the code for "Make the form in customize.php sticky, so that it reflects the user's current choices." I'm a total newbie when it comes to this stuff and it took me awhile to figure it out. Some how it works though so :D

    <?php // Script 9.3 - customize.php #2
    // Handle the form if it has been submitted:
    if (isset($_POST['font_size'], $_POST['font_color'])) {
    
    // Send the cookies:
    setcookie('font_size', $_POST['font_size'], time()+10000000, '/');
    setcookie('font_color', $_POST['font_color'], time()+10000000, '/');
    // Message to be printed later:
    $msg = '<p>Your settings have been entered! Click <a href="view_settings.php">here</a> to see them in action.</p>';
    
    } // End of submitted IF.
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Customize Your Settings</title>
     <style type="text/css">
    body {
    <?php // Script 9.2 - view_settings.php
    // Check for a font_size value:
    if (isset($_POST['font_size'])) { print "\t\tfont-size: " . htmlentities($_POST['font_size']) . ";\n"; }
    elseif (isset($_COOKIE['font_size'])) {
    print "\t\tfont-size: " . htmlentities($_COOKIE['font_size']) . ";\n";
    } else {
    print "\t\tfont-size: medium;";
    }
    // Check for a font_color value:
    if (isset($_POST['font_size'])) {print "\t\tcolor: #" . htmlentities($_POST['font_color']) . ";\n";}
    elseif (isset($_COOKIE['font_color'])) {
    print "\t\tcolor: #" . htmlentities($_COOKIE['font_color']) . ";\n";
    } else {
    print "\t\tcolor: #000;";
    }
    ?>
     }
    		</style>
    </head>
    <body>
    <?php // If the cookies were sent, print a message.
    if (isset($msg)) {
    print $msg;
    }
    ?>
    <p>Use this form to set your preferences:</p>
    <form action="customize.php" method="post">
    <select name="font_size">
    <option value="">Font Size</option>
    <option value="xx-small" <?php
    		if (isset($_POST['font_size']) && $_POST['font_size'] == 'xx-small')
    		{
    			print "selected";
    		}
    		elseif (isset($_COOKIE['font_size']) && $_COOKIE['font_size']=='xx-small')
    		{
    			print "selected";
    		}
    		?>>xx-small</option>
    <option value="x-small" <?php
    if (isset($_POST['font_size']) && $_POST['font_size'] == 'x-small')
    		{
    			print "selected";
    		}
    		elseif (isset($_COOKIE['font_size']) && $_COOKIE['font_size']=='x-small')
    		{
    			print "selected";
    		}
    
    		?>>x-small</option>
    <option value="small" <?php
    if (isset($_POST['font_size']) && $_POST['font_size'] == 'small')
    		{
    			print "selected";
    		}
    		elseif (isset($_COOKIE['font_size']) && $_COOKIE['font_size']=='small')
    		{
    			print "selected";
    		}
    
    		?>>small</option>
    <option value="medium" <?php
    if (isset($_POST['font_size']) && $_POST['font_size'] == 'medium')
    		{
    			print "selected";
    		}
    		elseif (isset($_COOKIE['font_size']) && $_COOKIE['font_size']=='medium')
    		{
    			print "selected";
    		}
    
    		?>>medium</option>
    <option value="large" <?php
    if (isset($_POST['font_size']) && $_POST['font_size'] == 'large')
    		{
    			print "selected";
    		}
    		elseif (isset($_COOKIE['font_size']) && $_COOKIE['font_size']=='large')
    		{
    			print "selected";
    		}
    
    		?>>large</option>
    
    <option value="x-large" <?php
    if (isset($_POST['font_size']) && $_POST['font_size'] == 'x-large')
    		{
    			print "selected";
    		}
    		elseif (isset($_COOKIE['font_size']) && $_COOKIE['font_size']=='x-large')
    		{
    			print "selected";
    		}
    
    		?>>x-large</option>
    <option value="xx-large" <?php
    if (isset($_POST['font_size']) && $_POST['font_size'] == 'xx-large')
    		{
    			print "selected";
    		}
    		elseif (isset($_COOKIE['font_size']) && $_COOKIE['font_size']=='xx-large')
    		{
    			print "selected";
    		}
    
    		?>>xx-large</option>
    </select>
    <select name="font_color">
    <option value="">Font Color</option>
    <option value="999">Gray</option>
    <option value="0c0">Green</option>
    <option value="00f">Blue</option>
    <option value="c00">Red</option>
    <option value="000">Black</option>
    </select>
    <input type="submit" name="submit" value="Set My Preferences" />
    </form>
    </body>
    </html>
    

×
×
  • Create New...