Jump to content
Larry Ullman's Book Forums

Jonathon

Members
  • Posts

    1064
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Jonathon

  1. Yes I do. That code doesn't work though (I don't think). You're thinking too big. The only difference in the password input field compared to the standard 'text' input is that it's type is called 'password'. Use the function code I gave you and call the first function like this make_text_input('first_name', 'First Name', 'text');
  2. Nope the function that I gave you is absolutely fine in achieving the output that is required. All you need to do is put the right values for the 3rd argument of the function. The 3rd argument is effectively stating is this a 'text' input field or a 'password' input field
  3. The source code you are aiming to achieve is this: <p><label>First Name: <input type="text" name="first_name" size="20" /></label></p> <p><label>Last Name: <input type="text" name="last_name" size="20" /></label></p> <p><label>Email Address: <input type="text" name="email" size="20" /></label></p> <p><label>Enter your password: <input type="password" name="password" size="20" /></label></p> <input type="submit" name="submit" value="Register!" />
  4. Ok well you want the outputted code to look like this <p><label>First Name: <input type="text" name="first_name" size="20" /></label></p> So call the function you have made and pass it 3 arguments. The function is defined as this: make_text_input($name, $label, $password) In your previous code you have done this: make_text_input('first_name', 'First Name', NULL); Which would generate this otuput <p><label>First Name: <input type="" name="first_name" size="20" /></label></p> Notice that the label is specified in the output, because you passed it as your 2nd argument to the function as 'First Name'. Also notice that the name is specified as "first_name" because you specified it as your first argument in the function. Then notice that the type="" ie there is no type specified, because you passed a value of NULL as the 3rd argument. If you can't do it from this i'll gladly tell you how to do the first input field bit
  5. Hello April, Look at the source code this generates, it will show you that the password field <input type="password" name="$password" size="20" /> So that should straight away tell you there is a problem. This is your problem invocation make_text_input ('password', 'Enter your password', '$password'); You never specify $password in the script. Password is in the function as an argument but you give it no value in the script where you use it.The function i gave you before will work. So use this code <?php // This function makes a sticky text input. // This function requires three arguments be passed to it. function make_text_input($name, $label, $password) { // Begin a paragraph and a label: print '<p><label>' . $label . ': '; // Begin the input: print '<input type="' . $password . '" name="' . $name . '" size="20" '; // Add the value: if (isset($_POST[$name])) { print ' value="' . htmlspecialchars($_POST[$name]) . '"'; } else { if (isset($_POST[$password])) { print ' value="' . htmlspecialchars($_POST[$password]) . '"'; } } // Complete the input, the label and the paragraph: print ' /></label></p>'."\n"; } // End of make_text_input() function. // Make the form: print '<form action="" method="post">'; // Create some text inputs: /******INVOKE FUNCTION TO MAKE INPUT FIELD HERE******** * first name input * last name input * email input * password input ***************************************************/ print '<input type="submit" name="submit" value="Register!" /></form>'; ?> Though you are probably frustrated with this, persevere you are a lot closer to fixing this than you think. You just need to call the functions with the right arguments for it to work and its done. Make sure you use the code I have left for you as it wont work with your previous attempt. I've also tidying the printing up so when you view the page source it will be over several lines not just one long line of code that's awkward to read. So to clarify at this stage all you need to do is call the functions (Where I have left lots of big comments in the code) and pass the correct arguments to them to make the input fields and you will be complete. Then if you are struggling how it fits together we'll walk through the code so you know how it all fits together.
  6. To invoke a function is to do this make_text_input('first_name', 'First Name', NULL); // This calls the function "make_text_input()" and passes it 3 arguments, 1 => 'first_name', 2 => 'First Name' and 3 => 'NULL' That is an example of how to invoke a function. If you ran the code I gave you in the last post, you should see no input boxes, because you haven't invoked the function. A clue is that the invocation i just showed you above, which is something you wrote earlier, will not work with those arguments. Just look at the code and notice that you need to pass an argument as $password. That argument is then used to help create the input which is this line here: print '<input type="' . $password . '" name="' . $name . '" size="20" ';
  7. Here is a pointer, All you have to do now is change the arguments you use to invoke the function in order to create the appropriate inputs. <?php // This function makes a sticky text input. // This function requires three arguments be passed to it. function make_text_input($name, $label, $password) { // Begin a paragraph and a label: print '<p><label>' . $label . ': '; // Begin the input: print '<input type="' . $password . '" name="' . $name . '" size="20" '; // Add the value: if (isset($_POST[$name])) { print ' value="' . htmlspecialchars($_POST[$name]) . '"'; } else { if (isset($_POST[$password])) { print ' value="' . htmlspecialchars($_POST[$password]) . '"'; } } // Complete the input, the label and the paragraph: print ' /></label></p>'; } // End of make_text_input() function. // Make the form: print '<form action="" method="post">'; // Create some text inputs: // Invoke functions here print '<input type="submit" name="submit" value="Register!" /></form>'; ?>
  8. Your function is: function make_text_input($name, $label, $password) So you need to take the values you provide to that function and use them within the code of the function itself. Currently this line: <input type="text" name="' . $name . '" size="20" '; Will always print you an input field with type="text" so edit that line so it can print either type="text" or type="password" depending on what $password argument you pass to the function? Follow?
  9. Well the first way to check it is, does the password field let you type plain text. The answer is probably yes. So in that case look at the source code, what does it return? All inputs are assigned a text value because off this line here: print '<input type="text" name="' . $name . '" size="20" '; So you need to make the above line be able to output either a password or text input. Currently you have hard coded "text" into the print statement so it will always return "text" as the input type. In short, you're not actually using the $password argument inside your function.
  10. Ask your host to try and alter this for you, it will save you a lot of time in the long run. Or work through the book on a local server.
  11. You are close, no errors is a thumbs up, the only problem you have here is that your password field will still be a text. If you try it out you will see that it accepts just plain text. So tweak your function in order for it to produce either text inputs or a password input field and it looks ok to me. (But you must remember I don't have the book so I cant explicitly say that).
  12. The ones i noted in the code i posted. What does your source code say then? Do you have display errors off?
  13. When you say not working, what do you mean? What errors (if any do you get?) One problem is that you haven't matched some quotes up <!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>Form Feedback</title> <style type="text/css" title="text/css" media="all"> .error { font-weight: bold; color: #C00; } </style> </head> <body> <?php # Script 2.4 - handle_form2.php #3 // Validate the name: if (!empty($_REQUEST['name'])) { $name = $_REQUEST['name']; } else { $name = NULL; echo '<p class="error">You forgot to enter your name!</p>'; } // Validate the email: if (!empty($_REQUEST['email'])) { $email = $_REQUEST['email']; } else { $email= NULL; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the comments: if (!empty($_REQUEST['comments'])) { $comments= $_REQUEST['comments']; } else { $comments = NULL; echo '<p class="error">You forgot to enter your comments!</p>'; } // Validate the gender: if (isset($_REQUEST['gender'])) { $gender = $_REQUEST['gender']; // missing closing ' if ($gender == 'M') { $greeting ='<p><b>Good day, Sir!</b></p>'; } elseif ($gender== 'F') { $greeting = '<p><b>Good day, Madam!</b></p>'; } else { //Unacceptable value. $gender=NULL; echo '<p class="error">Gender should be either "M" or "F"!</p>'; } } else { //$_REQUEST['gender'] is not set. $gender = NULL; echo '<p class="error">You forgot to select your gender!</p>'; } // If everything is OK, print the message: if ($name && $email && $gender && $comments) { echo "<p>Thank you, <b>$name</b>, for the following comments:<br /> <tt>$comments</tt></p> <p>We will reply to you at <i>$email</i>.</p>\n"; echo $greeting; } else { // Missing form value. echo '<p class="error">Please go back and fill out the form again.</p>'; } ?> </body> </html> The code you pasted now validated syntactically in my editor. What editor are you using, a good one should bring these oversights to your attention.
  14. No problem, I think Paul actually called it early doors. But glad it's working for you.
  15. I can see why that is confusing, but you are close to solving this April. Note that your function takes 4 arguments, So when you invoke this new function like so make_text_input('first_name', 'First Name'); You only specify 2 of the arguments, the $size argument is optional but optional arguments have to be declared last in the function. Then as Larry suggested you need to write an IF clause into the function body to help you generate either a 'text' or 'password' input type. We'll leave $_POST and $_GET till after this parts done.
  16. As I always like to do, when I find things that are useful (I think), I drop them into the forum. My latest find is the IE developer tools, which you access using F12. You can then render the current web page in different versions from IE 7 upwards. I thought this was really useful for IE as it totally sucks as a browser and i've never heard of it till now. Maybe some of you guys may also find it useful.
  17. Well its up to you. Your initial code suggested your BASE_URI was the root. Please note that you are not referencing your base_uri correctly, note the slashes are the wrong way and you need to end with a double \\ like I have. If you want the root to be the xamp folder then define ('BASE_URI', 'C:\xampp\\');
  18. Ok, well from what Larry says and you. You are trying to invoke a function called make_text_input(). But currently it doesn't have the ability to make a input type of password. It seems that Larry wants you to rewrite the make_text_input() function to be able to do so.
  19. Only for docs, I'll ammend the code, good spot Josee
  20. If you want your root to be your localhost then define ('BASE_URI', 'C:\xampp\htdocs\\'); Your BASE_URL needs to be the actual location you plan this site to be visible and work. If that's locally then it's this most likely define ('BASE_URL', 'http://localhost/')
  21. You need to run it through http:// I believe You can't run PHP through a file as far as i'm aware as it doesn't invoke the php parser. The url should be (i think, not 100% sure on your set up here, as I only glanced at it) http://localhost/phptest.php
  22. I don't have the book April, but it seems that you have taken type to be the GET and POST. Instead, remember that the function is trying to create different types of inputs for forms. Password is just another type of input as is text or textarea. Hope that helps.You will figure it out I'm sure :-)
  23. An IDE is an integrated development environment. They are often provide error highlighting and more in depth programming help like they can populate functions and language constructs, even custom functions. They usually provide good project overviews for including files and classes etc. Where as your regular editor provides a simpler kind of user interaction. I think what you have is fine, and its better in my opinion, it's better to type it all out by hand and get used to writing without prompts. I think context or Gedit provide better highlighting compared to Notepad++ which may help the code sink in better.
  24. I have Dreamweaver. But I did use to have Notepadd++, which I love for balancing braces, I have Context as I prefer its syntax highlighting, it's free also. I also have Gedit which is really good too, also free.
  25. Have you called phpinfo () with a space before the parenthesis?also are you actually declaring 2 doctypes?
×
×
  • Create New...