xaznbabyx Posted September 15, 2015 Share Posted September 15, 2015 i got it to change colors now I have to create an error and display the error message if they choose a color like black text and blue background etc. How would i create the error handling? http://hills.ccsf.edu/~schow11/cs130a/hw3.php Part IIn this part you will create a set of pages that could be used to test different text and background color combinations. Your first page should contain a form with two selection lists: one for the background color, and one for the text color. Your second page should process this form, displaying some sample text in the desired color with the desired background color. In addition, your program should display an error message (in black text on a white background) if the user selects the same color for both text and background. The specific colors you have in your selection lists are up to you, but you should have at least five colors in each list. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 15, 2015 Share Posted September 15, 2015 What have you tried so far? I guess you are using the code given to you in your last topic? and did you not learn any thing about handling input errors in your other topic? Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 15, 2015 Author Share Posted September 15, 2015 It is a different assignment Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 15, 2015 Share Posted September 15, 2015 Use the comparison operator to see if the values are the same, Simple if/else logic // When you get the background and text color from the user // check if the chosen background and text colors are the same if($background_color == $text_color) { // colors are the same so output error message saying colors must not be the same // set page background to be white and text color to black } // colors are not the same else { // so set the page background and text color to the chosen values. } Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 15, 2015 Author Share Posted September 15, 2015 (edited) http://hills.ccsf.edu/~schow11/cs130a/hw3.php i did somethign like this but the error isn't displaying.. also how do u place in the php format with the indentations? <?php //check if form submitted if (isset($_POST['submit'])) { //if below statements are true will overwrite the variable //check if textcolor is set if (isset($_POST['textcolor'])) { $textcolor = $_POST['textcolor']; print "<p>The text color you chose is $textcolor color</p>"; } //check if bgcolor is set if (isset($_POST['bgcolor'])) { $bgcolor = $_POST['bgcolor']; print "<p>The background color you chose is $bgcolor color"; } else { if($background_color == $text_color) print '<p class="error">Please do not choose the text and background color!"</p>'; } } ?> Edited September 15, 2015 by xaznbabyx Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 16, 2015 Share Posted September 16, 2015 Your if statement for comparing the colors should not be in an else statement. It must be on its own. Next you need to use the correct variable names, $background_color should be $bgcolor and $text_color should be $textcolor When you echo the error message you should be resetting $bgcolor and $textcolor back to their default values, which is black and white respectively. <?php //check if form submitted if (isset($_POST['submit'])) { //if below statements are true will overwrite the variable //check if textcolor is set if (isset($_POST['textcolor'])) { $textcolor = $_POST['textcolor']; print "<p>The text color you chose is $textcolor color</p>"; } //check if bgcolor is set if (isset($_POST['bgcolor'])) { $bgcolor = $_POST['bgcolor']; print "<p>The background color you chose is $bgcolor color"; } if($bgcolor == $textcolor) { print '<p class="error">Text and background color cannot be the same!"</p>'; // reset colors to default values $bgcolor = 'white'; $textcolor = 'black'; } } ?> how do u place in the php format with the indentations? When posting either wrap the code inside tags or click the <> button in the editor Quote Link to comment 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.