Jump to content

Really frustrating.


education81

Recommended Posts

Hi I have recently implemented a style sheet switcher to my site and is nearly complete.

I am very new to php so please be patient.

 

I have an index page that has the following

 

<form action="http://www.freestormtracker.com/scripts/s3.php" method="get">
           <label for="style">Style:</label>
                <select id="style" name="style">
                <?php
                    foreach ($available_styles as $_style) {
                        printf('<option value="%s"%s>%s</option>',
                               $_style,
                               ($_style == $style)
                                   ? ' selected="selected"'
                                   : '',
                               ucfirst($_style));
                    }
                ?>
                </select>
			<input type="submit" value="switch" />
			</form>

 

This form also uses  two other pages called s3.php and s3.cfg.php

 

S3 looks like

 

<?php
// vim:et ts=4 sw=4 cindent:

if (!@include('s3.cfg.php'))
    die("Unable to include config file!");

$set_cookie = true;

if (isset($_GET['style'])) {

    $style = $_GET['style'];

} elseif (isset($_POST['style'])) {

    $style = $_POST['style'];

} elseif (isset($_COOKIE['style'])) {

    $style = $_COOKIE['style'];
    $set_cookie = false;

}

// if no style supplied, or invalid supplied...
if (!isset($style)
    || !in_array($style, $available_styles)) {
    // set style to default (first available)
    $style = $available_styles[0];
}

// our cookie will last 2 years... modify
// the last argument if this isn't sufficient
if ($set_cookie)
    setcookie('style', $style,
              mktime() + 2 * 356 * 24 * 60 * 60,
              '/', '.freestormtracker.com');

$referrer = (!empty($_SERVER['HTTP_REFERER']))
    ? $_SERVER['HTTP_REFERER']
    : $default_referrer;

header('Location: ' . $referrer);

?>

 

and s3.cfg.php

 

<?php
// vim:et ts=4 sw=4 cindent:

    $style_path = 'http://www.freestormtracker.com/style/';

    $available_styles = array(
        'red',
        'default'
    );

    $default_referrer = '/';

?>

 

 

All i want is the index page to have clickable images  instead of a dropdown selection but i have no idea how to do this.

 

Ant help is very much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/185416-really-frustrating/
Share on other sites

well since you send it via get, you can make a link, (which would go to whateverpage.php (this is your action attribyte) and at the end of that you put ?style=$watever)

 

not to hard to change the code you have with images. just change the option tags to <a> tags wrapped around img tags

Link to comment
https://forums.phpfreaks.com/topic/185416-really-frustrating/#findComment-978839
Share on other sites

<a href="/style_switcher.php?style=blue"><img src="blue.png" alt="Blue Style" /></a>
<a href="/style_switcher.php?style=silver"><img src="silver.png" alt="Silver Style" /></a>
<a href="/style_switcher.php?style=red"><img src="red.png" alt="Red Style" /></a>

 

You can output links like that and then style_swither.php, or whatever script you want to link to, can perform the logic of setting the cookie and redirecting to an appropriate page.

Link to comment
https://forums.phpfreaks.com/topic/185416-really-frustrating/#findComment-978866
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.