Jump to content
Larry Ullman's Book Forums

Mark Spaghetti

Members
  • Posts

    11
  • Joined

  • Last visited

Mark Spaghetti's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. That is a good point that I had not considered. Of course, you can have php variables as part of html links and this is what I am trying to learn. But I can re-evaluate this now with the fact that this is primarily html. Thank you for your comments. Any others will be appreciated. And I like your book Larry. It is good for us non-Geek speaking programming wannabees. I hope all is well in PA. And reading your post again, I like your fundamental explanation. You are actually getting PHP to print the HTML for the link using PHP variables.
  2. I have another fundamental difficulty with PHP and I have not gotten any good instruction on this. I simply want to place a link on a page and when someone on the web page clicks on the link have it go to a certain file named web page. Are there any simple instructions for this? With html it is simple, but not with PHP, at least that I have seen.
  3. Hi Margaux: I agree with you 100% on the CSS. Combining different language code together in one line does make it more difficult. Part of the problem is our assignments have been very difficult for first semester PHP students. Also it is difficult to use an external CSS stylesheet with their server. It is difficult to figure out what folder to place the css file in and then when I use a regular path to it, it still does not read the CSS. Usually, the CSS has gone in the head section for my file work, but not always.
  4. Testing the code again. Maybe the code is O.K. afterall. When I tested it in the textarea, I just did not put any spaces in between letters so it ran the whole thing across the page. When I write regular words, it seems to work. First time I have been wrong for being right. Ha ha ha ha.
  5. I like this web site, but suddenly the text editor got turned off on my computer for this web site. I used to be able to click, for example, the color button and change the color of some text on one of my posts. It got turned off. I don't know why. I noticed this right after I clicked the Tab button. It should not have been turned off.
  6. Thank you Margaux. Good basic fundamental information from you and I appreciate it. I don't have time to study JavaScript now. I will just add maxlength into the textarea and specify HTML5 code. And if it reads it great. If it doesn't, I am not going to be concerned. I do have another problem now though. I am thinking I may need to add some string code for the new $comment variable because coming from the textarea form it is not reading the CSS that is part of this file. Below is the revised code. Any help is greatly appreciated. <!DOCTYPE html> <html lang="en"> <head> <meta charset=utf-8> <title>Mark Spaghetti PHP</title> <style type="text/css"> #ecardform { float:left; width:420px; margin: 1.2em 0em 1.2em 1.2em; font-size: 1.2em; } #message { float:left; width:420px; margin: 1.2em 0em 1.2em 1.2em; font-size: 1.2em; } #comments { float:left; width:400px; margin: 1.2em 0em 1.2em 1.2em; font-size: 1.2em; } body { font-size: 1.2em; } </style> </head> <body> <?php print '<style type="text/css" media="screen"> .error { color: red;} </style>'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $problem = FALSE; if (empty($_POST['sender']) && ((str_word_count($_POST['sender']) != 2) || (str_word_count ($_POST['sender']) != 3))) { $problem = TRUE; print '<p class="error">Please enter your first and last name.</p>'; } if (empty($_POST['sender_email']) || (substr_count($_POST['sender_email'], '@', 0) != 1)) { $problem = TRUE; print '<p class="error">Please enter your email address.</p>'; } if (empty($_POST['recipient']) && ((str_word_count($_POST['recipient']) != 2) || (str_word_count($_POST['recipient']) != 3))) { $problem = TRUE; print '<p class="error">Please enter the recipient\'s first and last name.</p>'; } if (empty($_POST['recipient_email']) || (substr_count($_POST['recipient_email'], '@', 0) != 1)) { $problem = TRUE; print '<p class="error">Please enter the recipient\'s e-mail address.</p>'; } if ( empty( $_POST['comments'] ) || ( strlen( $_POST['comments']) > 328 ) ) { $problem = TRUE; print '<p class="error">Please send the recipient a message that is 328 characters or less.</p>'; } if (!$problem) { $comments = $_REQUEST['comments']; $sender = $_REQUEST['sender']; print '<div id="message">' . '<p>Need to go to another page to send an email with the following.</p>' . $sender . ' has sent you an ecard with the following message:' . '<br /><br />' . $comments . '</div>'; //$_POST = array(); } else { print '<p class="error">Please try again.</p>'; } } ?> <div id="ecardform"> <form action="form_improve.php" method="post"> <p>Sender: <input type="text" name="sender" size="25" maxlength="30" value="<?php if (isset($_POST['sender'])) {print htmlspecialchars($_POST['sender']); } ?>" /> </p> <p>Sender e-mail: <input type="text" name="sender_email" size="35" maxlength="40" value="<?php if (isset($_POST['sender_email'])) {print htmlspecialchars($_POST['sender_email']); } ?>" /> </p> <p>Recipient: <input type="text" name="recipient" size="30" maxlength="25" value="<?php if (isset($_POST['recipient'])) {print htmlspecialchars($_POST['recipient']); } ?>" /> </p> <p>Recipient e-mail: <input type="text" name="recipient_email" size="35" maxlength="40" value="<?php if (isset($_POST['recipient_email'])) {print htmlspecialchars($_POST['recipient_email']); } ?>" /> </p> Message:<br /> <textarea name="comments" rows="7" cols="41" maxlength="328"><?php if (isset($_POST['comments'])) {print htmlspecialchars($_POST['comments']); } ?><textarea> <p> <input type="submit" name="preview_button" value="Preview your ecard" style="background-color:#FFCC00;border-color:#3333FF" /> </p> </form> </div> </body> </html>
  7. In researching the above, it looks like the HTML textarea element does not allow you to limit the number of characters for a textarea. In contrast the text input does allow HTML code that limits the number of characters. Maybe HTML5 will add more coding attributes, but I have not studied HTML5. However, with the above PHP code I did add to an if/else statement and limited the number of characters to 120. Maybe that is the best that I can do now. Thank you for your help.
  8. Hi Margaux: Thank you. The code you stated works well. I just tried it out. Good to know that html textarea does not accept values. I did not know that. Do you know code that limits the amount of characters inside the textarea that is part of the form element? Thanks again.
  9. Using the same basic code, the sticky form is not working for textarea. It works for input text, but not textarea. I don't know why PHP does not work. It has potential, but many minute problems. Below is the code with problem code in red. Thank you for your help. <?php print '<style type="text/css" media="screen"> .error { color: red;} </style>'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $problem = FALSE; if (empty($_POST['sender']) && ((str_word_count($_POST['sender']) != 2) || (str_word_count($_POST['sender']) != 3))) { $problem = TRUE; print '<p class="error">Please enter your first and last name.</p>'; } if (empty($_POST['sender_email']) || (substr_count($_POST['sender_email'], '@', 0) != 1)) { $problem = TRUE; print '<p class="error">Please enter your email address.</p>'; } if (empty($_POST['recipient']) && ((str_word_count($_POST['recipient']) != 2) || (str_word_count($_POST['recipient']) != 3))) { $problem = TRUE; print '<p class="error">Please enter the recipient\'s first and last name.</p>'; } if (empty($_POST['recipient_email']) || (substr_count($_POST['recipient_email'], '@', 0) != 1)) { $problem = TRUE; print '<p class="error">Please enter the recipient\'s e-mail address.</p>'; } if ( empty( $_POST['comments'] ) || ( strlen( $_POST['comments']) > 120 ) ) { $problem = TRUE; print '<p class="error">Please send the recipient a message that is 120 characters or less.</p>'; } if (!$problem) { print '<p>Need to go to another page to send an email with the following.</p>'; $sender = $_REQUEST['sender']; print $sender . ' has sent you an ecard with the following message:' . '<br /><br />'; $comments = $_REQUEST['comments']; print $comments; } else { print '<p class="error">Please try again.</p>'; } } ?> <form action="form_improve.php" method="post"> <p>Sender: <input type="text" name="sender" size="25" value="<?php if (isset($_POST['sender'])) {print htmlspecialchars($_POST['sender']); } ?>" /> </p> <p>Sender e-mail: <input type="text" name="sender_email" size="35" value="<?php if (isset($_POST['sender_email'])) {print htmlspecialchars($_POST['sender_email']); } ?>" /> </p> <p>Recipient: <input type="text" name="recipient" size="25" value="<?php if (isset($_POST['recipient'])) {print htmlspecialchars($_POST['recipient']); } ?>" /> </p> <p>Recipient e-mail: <input type="text" name="recipient_email" size="35" value="<?php if (isset($_POST['recipient_email'])) {print htmlspecialchars($_POST['recipient_email']); } ?>" /> </p> Message:<br /> <textarea name="comments" rows="7" cols="45" value="<?php if (isset($_POST['comments'])) {print htmlspecialchars($_POST['comments']); } ?>" > </textarea> <p> <input type="submit" name="preview_button" value="Preview your ecard" style="background-color:#FFCC00;border-color:#3333FF" /> </p> </form>
  10. Thank you for catching my typing error, which I copied and pasted. Good job Jonathon. Now the code WORKS! I am finishing a PHP class at City College of San Francisco. The class has been challenging. That is the thing about programming languages like PHP. All your 't's must be crossed, your 'I's must be dotted and your commas and periods in the right place or the code will not work. Thanks again. It is good to work with people more knowledgeable than I am. And sticky forms are important. Feel free to copy the above code, correct my error, make some content changes and additions and then reuse it on your web site.
  11. I like Larry Ullman's book "PHP for the Web" fourth edition. However, there is some code that says in the book it will create a sticky form. However, the code does not do that. Below is the code. People that are more knowledgeable than me for PHP please examine this. This code is from pages 210 through 216. I left out the following line of code because I do not want to take the time to write an additional file. The line of code that I left out from page 212 is the following: include('templates/header.html'); I also left out the include footer.html function/file, because I do not have the time to write the footer.html file. I think the sticky form should work without the header and footer and in viewing this code in the Internet Explorer browser there were no error messages. From Larry's book on page 210, it says "A sticky form remembers values entered into it. A common example is a search engine, which often displays your terms in the search box, even when showing the results of the search." Here is the code: /*define('TITLE, 'Register');*/ // Line of code also not used because it causes a parameter error.It is likely from the include file. print '<style type=text/css" media="screen"> .error { color: red;} </style>'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $problem = FALSE; if (empty($_POST['first_name'])) { $problem = TRUE; print '<p class="error">Please enter your first name</p>'; } if (empty($_POST['last_name'])) { $problem = TRUE; print '<p class="error">Please enter your last name</p>'; } if (empty($_POST['email'])) { $problem = TRUE; print '<p class="error">Please enter your email address.</p>'; } if (empty($_POST['password1'])) { $problem = TRUE; print '<p class="error">Please enter a password.</p>'; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print '<p class="error">Your password did not match your confirmed password.</p>'; } if (!$problem) { print '<p>You will soon be registered.</p>'; $_POST = array(); } else { print '<p class="error">Please try again.</p>'; } } ?> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="20" value="<?php if (isset($POST['first_name'])) {print htmlspecialchars($_POST['first_name']); } ?>" /> </p> <p>Last Name: <input type="text" name="last_name" size="20" value="<?php if (isset($POST['last_name'])) {print htmlspecialchars($_POST['last_name']); } ?>" /> </p> <p>Email address: <input type="text" name="email" size="20" value="<?php if (isset($POST['email'])) {print htmlspecialchars($_POST['email']); } ?>" /> </p> <p>Password: <input type="password" name="password1" size="20" value="<?php if (isset($POST['password1'])) {print htmlspecialchars($_POST['password1']); } ?>" /> </p> <p>Confirm Password: <input type="password" name="password2" size="20" value="<?php if (isset($POST['password2'])) {print htmlspecialchars($_POST['password2']); } ?>" /> </p> <p> <input type="submit" name="submit" value="Register" /></p> </form> <?php /*include('templates/footer.html');*/ ?> <!-- The footer.html file also not included.-->
×
×
  • Create New...