Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About hugo

  • Rank
  1. It works now: I was missing the method. Thanks for catching that mistake Hartley. However, it was strange-all my scripts, not just the one I posted was spitting out only the PHP source code. My scripts work now although I have no idea what I did. I tried shutting off and turning back on XAMPP and also made sure to use Save As in Notepad++; perhaps these steps helped? I don't know. I'm so glad the scripts are working now, phew!
  2. Yeah, I just tried typing in http://localhost/script_03_01.html into my browser, then I filled out the form and got this output: Notice: Undefined index: title in C:\xampp\htdocs\handle_form.php on line 15 Notice: Undefined index: name in C:\xampp\htdocs\handle_form.php on line 16 Notice: Undefined index: response in C:\xampp\htdocs\handle_form.php on line 17 Notice: Undefined index: comments in C:\xampp\htdocs\handle_form.php on line 18 Thank you, , for your comments. You stated that you found this example to be '' and added: I'm kinda confused now: Am I supposed to open the HTML file in my browser then fill out the form and submit it? Or, am I supposed to run the HTML through local host as well? (as well at the PHP file which I have been running through local host--to test if I could simply send html created by PHP to the browser). In anycase, I can't seem to get the scripts to work. I'm still stumped.
  3. Hi Hartley, Yes I ran php_info(); and all the information is shown neatly in a long grid. I'm still stumped as to why the php output is like that. I double clicked the HTML form which opens in Mozilla, then I filled in the form and pressed the submit button. The php output that returns is strange. Can you please help?
  4. For some reason XAMPP Apache is no longer working--it was working before. To be sure, I downloaded Larry's HTML and PHP scripts (from OReilly Website) and tested them; and the output I received in my browser was: Thank you, $title $name, for your comments. You stated that you found this example to be '$response' and added: $comments "; ?> The HTML file downloaded is Script_03_01.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Feedback Form</title> </head> <body> <!-- Script 3.1 - feedback.html --> <div><p>Please complete this form to submit your feedback:</p> <form action="handle_form.php"> <p>Name: <select name="title"> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Ms.">Ms.</option> </select> <input type="text" name="name" size="20" /></p> <p>Email Address: <input type="text" name="email" size="20" /></p> <p>Response: This is... <input type="radio" name="response" value="excellent" /> excellent <input type="radio" name="response" value="okay" /> okay <input type="radio" name="response" value="boring" /> boring</p> <p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p> <input type="submit" name="submit" value="Send My Feedback" /> </form> </div> </body> </html> The downloaded PHP file is Script_03_03.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Your Feedback</title> </head> <body> <?php // Script 3.3 handle_form.php // This page receives the data from feedback.html. // It will receive: title, name, email, response, comments, and submit in $_POST. // Create shorthand versions of the variables: $title = $_POST['title']; $name = $_POST['name']; $response = $_POST['response']; $comments = $_POST['comments']; // Print the received data: print "<p>Thank you, $title $name, for your comments.</p> <p>You stated that you found this example to be '$response' and added:<br />$comments</p>"; ?> </body> </html> I'm also not sure if this is relevant but I'm not currently using a genuine Windows 7 version (which was working just fine before). Can someone please help? Thanks in advance.
  5. Sorry, Larry it was my mistake. I should have checked the errata before posting. I've been so captivated to learn from your book that I had not considered the errata! Thanks, I understand now.
  6. I'm still having difficulty understanding this. On pg 136, the text says that the statement: if (!isset($_POST['terms'])) { could be written more exact by changing it to: if (!isset($_POST['terms']) AND ($_POST['terms']=='Yes')) { Question: Is the bolded segment a typo? Instead, should the statement be written as: if (!isset($_POST['terms']) AND ($_POST['terms'] !='Yes') { error message.... That way, if the person filling the form does not check the box, both these conditions become TRUE in order to trigger the error message? Your help is appreciated. Thanks in advance.
  7. Thank you very much! The code works now. Can you recommend a good source of reading on proper and/or non-sloppy code formatting? I've found several sources online after running a google search, but am not sure which one to trust. Your advice is highly appreciated. Thanks in advance.
  8. I'm having trouble with the following javascript code: function process() { 'use strict'; var okay=true; var email = document.getElementById('email'); var comments=document.getElementById('comments'); if(!email || !email.value || (email.value.length < 6) || (email.value.indexOf('@')= = -1)) { okay=false; alert('Please enter a valid email address'); } if(!comments || !comments.value || (comments.value.indexOf('<') != -1)) { okay=false; alert('Please enter your comments without any HTML!'); } return okay; } function init(){ 'use strict'; document.getElementById('conForm').onsubmit = process; } window.onload = init; Problem: After entering a valid email address in the HTML form, I go on to enter a < character in the comments box;the second conditional does not fire off after submitting the form. I've already checked the errata and downloaded the .zip file for the chapter and compared line by line. I've typed the code correctly as shown in the book. For testing, I commented out the first conditional using /* and */ and afterwards, I am able to get the second conditional to activate after typing in a < character in the text area. Question: How would I get both conditionals to function at the same time? That is, after entering a valid email address, but entering a prohibited character in the comments box?
  9. Hey Hartley, can you please help me understand why years.value is a string value? I thought years.value is by default a number object because of this line of code in the html document: <div> <label for="years">Years</label> <input type="number" name="years" id="years" min="1" required> </div> It says input type="number" which I have assumed the digits entered by the person filling the webform to be a number object. Why is this a string value? Can you refer me to further reading or help explain it? I am new to programming so any explanation you are giving is very helpful. Thank you!
  10. I also wish to add that I changed the code to: function calculate() { 'use strict'; var cost; var type=document.getElementById('type'); var years=document.getElementById('years'); if(type && type.value && years && (years.value>0)) { switch(type.value){ case 'basic': cost=10.00; break; case 'premium': cost=15.00; break; case 'gold': cost=20.00; break; case 'platinum': cost=25.00; break; } cost *= years.value; if(years.value>1){ cost*=0.80; //A 20% discount. } document.getElementById('cost').value='$'+ cost.toFixed(2); } else { document.getElementById('cost').value = 'Please enter valid values.'; } return false; } function init(){ 'use strict'; document.getElementById('memForm').onsubmit=calculate; } window.onload=init; Note: I took out the parseInt line of code in Step #4. And changed years to years.value in the rest of the code. As a result of these 2 changes to code works! If I understand correctly, after using this line of code: var years=document.getElementById('years'); I am allowed to refer to years (the object) and years.value (the value of the object). If I am wrong on this please let me know.
  11. Thank you very much! I think I understand now.
  12. Hello fellow programmers: I need help with Step #5 (page 147): if (type && type.value && years && (years>0)) { Question: When I replace years >0 with years.value >0, the program crashes--returns the please enter valid values message. Why doesn't this work? FYI: Step #3: var years = document.getElementById('years'); Thanks in advance.
  13. Hello Larry and other forum users, I have trouble understanding the code on page 136: if (!isset($_POST['terms']) AND ($_POST['terms']=='Yes')) { print '<p class="error">You must agree to the terms.</p>'; $okay=FALSE; } Question(s): 1. Why do I need to include ($_POST['terms'] =='Yes' ? 2. If i only include this code in the document: if ($_POST['terms'] !='Yes') { etc. } then i get the error message in my Mozilla browser: Notice: Undefined index: terms in C:\xampp\htdocs\handle_reg.php on line 76 The code in red still prints out, but this strange error message appears above it. 3. For further testing, if i include only the code: if ($_POST['terms'] == 'Yes') { print '<p class="error">You must agree to the terms.</p>'; $okay=FALSE; } and after I check the "agree to terms" box(in the register.html document) then the "You must agree to terms" statement in red appears as expected. But, the undefined index/error message does not appear. *So, I'm confused why there is an undefined index error message and what it means in question #2.* 4. Lastly, if I type in the entire code block as shown on page 136: if (!isset($_POST['terms']) AND ($_POST['terms']=='Yes')) { print '<p class="error">You must agree to the terms.</p>'; $okay=FALSE; } The same undefined error index message appears. I'm not sure what's wrong. Please help and thank you in advance.
  • Create New...