Jump to content

Input Text and choose font family, size and color, HEEEELLLPPPP!!!


noobtopro

Recommended Posts

Hello Everyone,

                      I am a noob at PHP so please forgive me if my code is wrong. I have a strong understanding of HTML and CSS  just for the curious.

 

Question: Write a program that formats a block of text (to be input by the user) based on preferences chosen by the user. Give your user options for color of text, font choice and size. Display output on a new page. I would greatly appreciate someone's help. The text is showing up but not according to the options selected. I know there is something wrong with the output page.

 

Here is the Input Page (call it question4.php):

 

<html>

<head>

<title>

Please Enter Your Text</title>

</head>

 

<body>

 

 

 

<form method="post" action="question4display.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="submit" name="submit" value="Submit" />

</form>

 

 

</body>

</html>

 

 

 

 

Here is the OUTPUT page (called it:question4display.php):

 

 

<?php

 

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: ' . $_POST['font'] . '; ';

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

echo 'color: ' . $_POST['color'] . '; ';

?> >

<?php

echo $_POST['textformat'];

?>

</p>

 

</body>

</html>

 

 

 

Link to comment
Share on other sites

You need to close the " around the styles

 

<?php

session_start();
$_SESSION['textformat'] = $_POST['textformat'];
$_SESSION['font'] = $_POST['font'];
$_SESSION['size'] = $_POST['size'];
$_SESSION['color'] = $_POST['color'];

?>

<html>
<head>
<title>No title</title>
</head>
<body>
<p
<?php
echo ' style="font-family: ' . $_POST['font'] . '; ';
echo 'font-size: ' . $_POST['size'] . '; ';
echo 'color: ' . $_POST['color'] . '; "';
?> >
<?php
echo $_POST['textformat'];
?>
</p>

</body>
</html>

Link to comment
Share on other sites

Lol I just got it right when you posted. I still don't fully understand the logic with the  . ';" '; stuff (my book is not very elaborate with explaining it)  but it works now. Thanks for the help, greatly appreciated.

Link to comment
Share on other sites

I still don't fully understand the logic with the  . ';" '; stuff

It is because you're outputting CSS. PHP and CSS statements must be ended with a semi-colon at the end of the line. A better way to code this

<p
<?php
echo ' style="font-family: ' . $_POST['font'] . '; ';
echo 'font-size: ' . $_POST['size'] . '; ';
echo 'color: ' . $_POST['color'] . '; "';
?> >

Could be as

<p style="font-family: <?php echo $_POST['font'] ?>; font-size: <?php echo $_POST['size'] ?>; color: <?php echo $_POST['color']?>;">

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.