Jump to content
Larry Ullman's Book Forums

speedyrb

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by speedyrb

  1. Sure thing, Alex. This is what I meant...

     

    Here's the key code from view_settings.php:

     

    <style type="text/css">
    body {
    <?php // Script 9.2 - view_settings.php
    
    // Check for a font_size value:
    if (isset($_COOKIE['font_size'])) {
    print "		font-size: " . htmlentities($_COOKIE['font_size']) . ";\n";		
    } else {
    print "		font-size: medium;";
    }
    
    // Check for a font_color value:
    if (isset($_COOKIE['font_color'])) {
    print "		color: #" . htmlentities($_COOKIE['font_color']) . ";\n";
    } else {
    print "		color: #000;";
    }
    
    ?>
    }
    </style>

     

    So to get that to work in customize.php, which also needs to be aware of the posted form, the code would be:

     

     

    <style type="text/css">
    body {
    <?php // Script 9.2 - view_settings.php
    
    // Check for a font_size value:
    if (isset($_COOKIE['font_size'])) {
    print "		font-size: " . htmlentities($_COOKIE['font_size']) . ";\n";		
    } elseif (isset($_POST['font_size'])) {
    print "		font-size: " . htmlentities($_POST['font_size']) . ";\n";		
    } else {
    print "		font-size: medium;";
    }
    
    // Check for a font_color value:
    if (isset($_COOKIE['font_color'])) {
    print "		color: #" . htmlentities($_COOKIE['font_color']) . ";\n";
    } elseif (isset($_POST['font_color'])) {
    print "		color: #" . htmlentities($_POST['font_color']) . ";\n";
    } else {
    print "		color: #000;";
    }
    
    ?>
    }
    </style>

     

    Note that there's an error in the prompt, in that the form uses POST, not GET. Let me know if you still have questions about this.

     

    When I tried the above, I found that when returning to customize.php from view_settings.php, the correct settings would be present on the "Use this form to set your preferences" text, but when selecting the font size and color on customize.php and hitting the "Set my preferences!" submit button, the previous settings would be in effect, not the ones just selected.

     

    Was this due to the conditional structure which looks at the $_COOKIE array before the $_POST array? When I switched these and made it look at the $_POST array first, and then 'elseif' look at the $_COOKIE array, it behaved as expected.

     

    I'm very new at this and am trying to make sure I understand...

  2. Hello!

     

    Here is what I arrived at for the 4th "Pursue" assignment:

     

    Up in the <head>

    <style type="text/css" media="screen">

    .blue { color: blue; }

    .green { color: green; }

    .red { color: red; }

    .yellow { color: yellow;}

    </style>

     

    And then down in the "success message" section:

    $color = $_POST['color'];

    print "<p>Your favorite color is <span class=\"$color\">$color</span> and is a $color_type color.</p>";

     

    Seems to work OK, but no concatenation (as suggested in the intructions). Is there a more efficient way to have accomplished this?

     

    Also, Larry, wondering if you have made your own versions of the "pursue" scripts available for download? If not, a suggestion for the future - I know I would find it helpful to have them to compare to.

     

    Thanks!

×
×
  • Create New...