noobtopro Posted May 1, 2011 Share Posted May 1, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/235234-input-text-and-choose-font-family-size-and-color-heeeelllpppp/ Share on other sites More sharing options...
teddyb Posted May 1, 2011 Share Posted May 1, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/235234-input-text-and-choose-font-family-size-and-color-heeeelllpppp/#findComment-1208853 Share on other sites More sharing options...
noobtopro Posted May 1, 2011 Author Share Posted May 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235234-input-text-and-choose-font-family-size-and-color-heeeelllpppp/#findComment-1208854 Share on other sites More sharing options...
wildteen88 Posted May 1, 2011 Share Posted May 1, 2011 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']?>;"> Quote Link to comment https://forums.phpfreaks.com/topic/235234-input-text-and-choose-font-family-size-and-color-heeeelllpppp/#findComment-1208971 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.