Jump to content

Saving Input Settings in a COOKIE


noobtopro

Recommended Posts

Hello again everyone,

                                I know someone knows how to do this.

 

Question: In the program you created in question 4, allow your user the option of saving the information for the next time they visit. If they choose "yes", save information in a cookie.

 

1st part of Question (I have done): Created a text input with options to select font family, font size, and font color.

 

At the bottom of question5.php I added a checkbox to save the information. I then created an if statement on the processing page (question5display.php. I would appreciate some help, thanks guys.

 

Here is the form ( called it question5.php):

 

<html>

<head>

<title>

Please Enter Your Text</title>

</head>

 

<body>

 

 

 

<form method="post" action="question5display.php">

 

<p>Enter the text you want formatted please:

 

<input type="text" name="textformat" maxlength="30" size="30" />

 

<table>

<tr>

  <td><label for="font">Select Font:</label></td>

  <td><select id="font" name="font">

  <option value="Verdana">Verdana</option>

  <option value="Arial">Arial</option>

  <option value="Times New Roman">Times New Roman</option>

</select>

</td>

</tr>

 

<tr>

  <td><label for ="size">Select Size:</label></td>

  <td><select id="size" name="size">

  <option value="10px">10px</option>

  <option value="12px">12px</option>

  <option value="14px">14px</option>

  <option value="20px">20px</option>

 

</select>

</td>

</tr>

 

<tr>

  <td><label for="color">Select Color:</label></td>

  <td><select id="color" name="color">

  <option value="green">Green</option>

  <option value="blue">Blue</option>

  <option value="red">Red</option>

  </select>

</td>

</tr>

 

 

</table>

 

<input type="checkbox" id="save_prefs" name="save_prefs" />

<label for="save_prefs">Save these preferences for the next time you log in.</label>

 

  <input type="submit" name="submit" value="Submit" />

</form>

 

 

</body>

</html>

 

 

 

 

 

 

Here is the page it goes to (called it question5display):

 

 

 

<?php

 

if (isset($_POST['save_prefs'])) {

  setcookie('font', $_POST['font'], time() + 60);

  setcookie('size', $_POST['size'], time() + 60);

  setcookie('color', $_POST['color'], time() + 60);

 

  $_COOKIE['font'] = $_SESSION['font'];

  $_COOKIE['size'] = $_SESSION['size'];

  $_COOKIE['color'] = $_SESSION['color'];

 

 

}

 

 

session_start();

$_SESSION['textformat'] = $_POST['textformat'];

$_SESSION['font'] = $_POST['font'];

$_SESSION['size'] = $_POST['size'];

$_SESSION['color'] = $_POST['color'];

 

 

?>

 

 

<html>

<head>

</head>

<body>

<p

<?php

echo ' style="font-family: ' . $_SESSION['font'] . '; ';

echo 'font-size: ' . $_SESSION['size'] . '; ';

echo 'color: ' . $_SESSION['color'] . ';" ';

?>>

<?php

echo $_SESSION['textformat'];

?>

</p>

 

 

</body>

</html>

Link to comment
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.